Skip to main content
Glama

SourceSage MCP

tool-handlers.ts2.55 kB
import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError, } from '@modelcontextprotocol/sdk/types.js'; import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { isGenerateStructureArgs } from '../utils/validation.js'; import { StructureGenerator } from '../services/structure-generator.js'; export class ToolHandlers { private structureGenerator: StructureGenerator; constructor(private server: Server) { this.structureGenerator = new StructureGenerator(); this.setupHandlers(); } /** * ツールハンドラーを設定する */ private setupHandlers(): void { this.setupListToolsHandler(); this.setupCallToolHandler(); } /** * 利用可能なツール一覧を返すハンドラーを設定 */ private setupListToolsHandler(): void { this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'generate_structure', description: 'プロジェクトのディレクトリ構造を生成し、ファイル内容も含めた詳細なドキュメントを作成します。プロジェクトやリポジトリ、フォルダの内容を理解するときに使用します。', inputSchema: { type: 'object', properties: { path: { type: 'string', description: '構造を生成するディレクトリの絶対パス', }, ignorePath: { type: 'string', description: '.SourceSageignoreファイルの絶対パス(オプション)', }, }, required: ['path'], }, }, ], })); } /** * ツール実行ハンドラーを設定 */ private setupCallToolHandler(): void { this.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name !== 'generate_structure') { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } if (!isGenerateStructureArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid arguments for generate_structure' ); } const structure = await this.structureGenerator.generateStructure(request.params.arguments); return { content: [ { type: 'text', text: structure, }, ], }; }); } }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Sunwood-ai-labs/source-sage-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server