feat(lib): bundle MCP servers from .common/lib into factory/lib/
Copies source (no node_modules, dist, .tasks, .wiki, __pycache__) for: - projects-meta-mcp v2.25.0 (TypeScript/Node) - wiki-graph v0.3.1 (TypeScript/Node) - interns-mcp v0.3.3 (Python/FastMCP) .gitignore: exclude lib build artefacts (node_modules, dist, .venv, __pycache__, *.pyc) bootstrap.ps1: add MCP build step — npm install+build for TS servers, venv+pip for Python Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
55
lib/wiki-graph/src/server.ts
Normal file
55
lib/wiki-graph/src/server.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
||||
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
||||
import {
|
||||
CallToolRequestSchema,
|
||||
ListToolsRequestSchema,
|
||||
type ServerResult,
|
||||
} from '@modelcontextprotocol/sdk/types.js';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { GraphCache } from './cache.js';
|
||||
import { makeWikiGraphTools } from './tools.js';
|
||||
|
||||
function readPackageVersion(): string {
|
||||
const pkgUrl = new URL('../package.json', import.meta.url);
|
||||
const pkg = JSON.parse(readFileSync(pkgUrl, 'utf8')) as { version?: unknown };
|
||||
if (typeof pkg.version !== 'string' || pkg.version.length === 0) {
|
||||
throw new Error(`package.json at ${pkgUrl.pathname} missing string "version" field`);
|
||||
}
|
||||
return pkg.version;
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const cache = new GraphCache();
|
||||
const tools = makeWikiGraphTools(cache);
|
||||
const byName = new Map(tools.map((t) => [t.name, t]));
|
||||
|
||||
const server = new Server(
|
||||
{ name: 'wiki-graph', version: readPackageVersion() },
|
||||
{ capabilities: { tools: {} } },
|
||||
);
|
||||
|
||||
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
||||
tools: tools.map((t) => ({
|
||||
name: t.name,
|
||||
description: t.description,
|
||||
inputSchema: t.inputSchema,
|
||||
})),
|
||||
}));
|
||||
|
||||
server.setRequestHandler(CallToolRequestSchema, async (req): Promise<ServerResult> => {
|
||||
const tool = byName.get(req.params.name);
|
||||
if (!tool) {
|
||||
return {
|
||||
content: [{ type: 'text', text: `Unknown tool: ${req.params.name}` }],
|
||||
isError: true,
|
||||
};
|
||||
}
|
||||
// ToolResult is a structural CallToolResult; cast over the widened SDK union.
|
||||
return tool.handler(req.params.arguments ?? {}) as ServerResult;
|
||||
});
|
||||
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
}
|
||||
|
||||
await main();
|
||||
Reference in New Issue
Block a user