/**
* Self MCP Server - Resources
* Recursos expostos para leitura do Self
*/
import defaultDb from '../db/index.js'
import { createMarkdownGenerator } from '../lib/markdown.js'
/**
* Definição de todos os resources do MCP
*/
export const resourceDefinitions = [
{
uri: 'self://profile/markdown',
name: 'Self Profile (Markdown)',
description: 'O perfil Self completo em formato Markdown',
mimeType: 'text/markdown',
},
{
uri: 'self://profile/json',
name: 'Self Profile (JSON)',
description: 'O perfil Self completo em formato JSON estruturado',
mimeType: 'application/json',
},
{
uri: 'self://foundations',
name: 'Fundamentos',
description: 'Valores, anti-valores e identidade futura',
mimeType: 'application/json',
},
{
uri: 'self://intentions',
name: 'Intenções',
description: 'Problemas, curiosidades, identidades e experiências que movem o usuário',
mimeType: 'application/json',
},
{
uri: 'self://missions',
name: 'Missões',
description: 'Missões de longo prazo',
mimeType: 'application/json',
},
{
uri: 'self://goals',
name: 'Metas',
description: 'Metas anuais',
mimeType: 'application/json',
},
{
uri: 'self://projects',
name: 'Projetos',
description: 'Projetos ativos, pausados e concluídos',
mimeType: 'application/json',
},
{
uri: 'self://obstacles',
name: 'Obstáculos',
description: 'Obstáculos e estratégias para superá-los',
mimeType: 'application/json',
},
{
uri: 'self://daily',
name: 'Registro Diário',
description: 'Vitórias, aprendizados e desvios registrados',
mimeType: 'application/json',
},
{
uri: 'self://daily/history',
name: 'Histórico Diário Completo',
description: 'Todo o histórico de registros diários',
mimeType: 'application/json',
},
]
/**
* Cria função readResource com instância de db injetada
* @param {Object} db - Instância do banco de dados (funções)
* @returns {Function} Função readResource
*/
export function createResourceReader(db) {
const generateMarkdown = createMarkdownGenerator(db)
return function readResource(uri) {
switch (uri) {
case 'self://profile/markdown':
return {
contents: [
{
uri,
mimeType: 'text/markdown',
text: generateMarkdown(),
},
],
}
case 'self://profile/json':
return {
contents: [
{
uri,
mimeType: 'application/json',
text: JSON.stringify(db.getFullProfile(), null, 2),
},
],
}
case 'self://foundations':
return {
contents: [
{
uri,
mimeType: 'application/json',
text: JSON.stringify(
{
values: db.getFoundationsByType('value'),
antiValues: db.getFoundationsByType('anti_value'),
identity: db.getFoundationsByType('identity'),
},
null,
2
),
},
],
}
case 'self://intentions':
return {
contents: [
{
uri,
mimeType: 'application/json',
text: JSON.stringify(
{
all: db.getIntentions(),
primary: db.getPrimaryIntention(),
byType: {
problems: db.getIntentionsByType('problem'),
curiosities: db.getIntentionsByType('curiosity'),
identities: db.getIntentionsByType('identity'),
experiences: db.getIntentionsByType('experience'),
},
},
null,
2
),
},
],
}
case 'self://missions':
return {
contents: [
{
uri,
mimeType: 'application/json',
text: JSON.stringify(db.getMissions(), null, 2),
},
],
}
case 'self://goals':
const currentYear = new Date().getFullYear()
return {
contents: [
{
uri,
mimeType: 'application/json',
text: JSON.stringify(
{
all: db.getGoals(),
currentYear: db.getGoals(currentYear),
},
null,
2
),
},
],
}
case 'self://projects':
return {
contents: [
{
uri,
mimeType: 'application/json',
text: JSON.stringify(
{
all: db.getProjects(),
active: db.getProjects('active'),
paused: db.getProjects('paused'),
done: db.getProjects('done'),
},
null,
2
),
},
],
}
case 'self://obstacles':
return {
contents: [
{
uri,
mimeType: 'application/json',
text: JSON.stringify(
{
all: db.getObstacles(),
active: db.getObstacles(false),
resolved: db.getObstacles(true),
},
null,
2
),
},
],
}
case 'self://daily':
return {
contents: [
{
uri,
mimeType: 'application/json',
text: JSON.stringify(
{
recent: db.getDaily(20),
victories: db.getDailyByType('victory', 10),
learnings: db.getDailyByType('learning', 10),
deviations: db.getDailyByType('deviation', 10),
},
null,
2
),
},
],
}
case 'self://daily/history':
return {
contents: [
{
uri,
mimeType: 'application/json',
text: JSON.stringify(
{
history: db.getDaily(365), // Fetch last year of entries
},
null,
2
),
},
],
}
default:
throw new Error(`Resource não encontrado: ${uri}`)
}
}
}
// Backward compatibility: export readResource using default db
export const readResource = createResourceReader(defaultDb)
export default { resourceDefinitions, readResource, createResourceReader }