MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / registerResources

Function registerResources

packages/mcp-server/src/server.ts:88–162  ·  view source on GitHub ↗
(server: McpServer, dbManager: McpDatabaseManager)

Source from the content-addressed store, hash-verified

86}
87
88function registerResources(server: McpServer, dbManager: McpDatabaseManager): void {
89 server.resource('sessions-list', 'chatlab://sessions', { description: '所有已导入的聊天会话列表' }, async () => {
90 const sessionIds = dbManager.listSessionIds()
91 const sessions = sessionIds
92 .map((id) => {
93 const db = dbManager.open(id)
94 if (!db) return null
95 const meta = getSessionMeta(db)
96 if (!meta) return null
97 return { id, name: meta.name, platform: meta.platform, type: meta.type }
98 })
99 .filter(Boolean)
100
101 return {
102 contents: [
103 {
104 uri: 'chatlab://sessions',
105 text: JSON.stringify(sessions, null, 2),
106 mimeType: 'application/json',
107 },
108 ],
109 }
110 })
111
112 server.resource(
113 'session-meta',
114 new ResourceTemplate('chatlab://sessions/{sessionId}/meta', { list: undefined }),
115 { description: '会话元信息(名称、平台、消息数等)' },
116 async (uri, params) => {
117 const sessionId = params.sessionId as string
118 const db = dbManager.open(sessionId)
119 if (!db) {
120 return { contents: [{ uri: uri.href, text: '{"error": "Session not found"}', mimeType: 'application/json' }] }
121 }
122
123 const meta = getSessionMeta(db)
124 const overview = getSessionOverview(db)
125
126 return {
127 contents: [
128 {
129 uri: uri.href,
130 text: JSON.stringify({ ...meta, ...overview }, null, 2),
131 mimeType: 'application/json',
132 },
133 ],
134 }
135 }
136 )
137
138 server.resource(
139 'session-schema',
140 new ResourceTemplate('chatlab://sessions/{sessionId}/schema', { list: undefined }),
141 { description: '会话数据库的表结构' },
142 async (uri, params) => {
143 const sessionId = params.sessionId as string
144 const db = dbManager.open(sessionId)
145 if (!db) {

Callers 1

startMcpServerFunction · 0.85

Calls 5

getSessionMetaFunction · 0.90
getSessionOverviewFunction · 0.90
getDatabaseSchemaFunction · 0.90
listSessionIdsMethod · 0.65
openMethod · 0.65

Tested by

no test coverage detected