mcpjam_search_mcp_spec
Search the Model Context Protocol specification to retrieve detailed documentation on sections like Tools, Resources, Authorization, and other protocol components.
Instructions
Search the MCP specification document for relevant content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Select a specific section of the MCP specification to retrieve. |
Implementation Reference
- src/index.ts:141-169 (handler)The execute function implementing the tool's core logic: loads document chunks, performs exact section match on query parameter, returns section content as JSON or handles errors.execute: async (args) => { const fuse = loadAndIndexDocument(); try { if (!fuse) { throw new UserError("Search index not initialized. Please try again."); } // Find exact section match const matchingChunk = documentChunks.find( (chunk) => chunk.section === args.query ); if (!matchingChunk) { return `No section found with the name "${args.query}".`; } return JSON.stringify( { content: matchingChunk.content, }, null, 2 ); } catch (error) { return `Search error: ${ error instanceof Error ? error.message : "Unknown error" }`; } },
- src/index.ts:99-140 (schema)Zod input schema defining the 'query' parameter as an enum of predefined MCP specification section names.parameters: z.object({ query: z .enum([ "Introduction", "Core components", "Connection lifecycle", "Elicitation", "Prompts", "Resources", "Roots", "Sampling", "Tools", "Transports", "Debugging", "Follow logs in real-time", "For Client Developers", "For Server Developers", "Architecture", "Authorization", "Lifecycle", "Security Best Practices", "Transports", "Cancellation", "Ping", "Progress", "Elicitation", "Roots", "Sampling", "Specification", "Overview", "Prompts", "Resources", "Tools", "Completion", "Logging", "Pagination", "Versioning", ]) .describe( "Select a specific section of the MCP specification to retrieve." ), }),
- src/index.ts:96-170 (registration)Registration of the 'mcpjam_search_mcp_spec' tool on the FastMCP server instance.server.addTool({ name: "mcpjam_search_mcp_spec", description: "Search the MCP specification document for relevant content", parameters: z.object({ query: z .enum([ "Introduction", "Core components", "Connection lifecycle", "Elicitation", "Prompts", "Resources", "Roots", "Sampling", "Tools", "Transports", "Debugging", "Follow logs in real-time", "For Client Developers", "For Server Developers", "Architecture", "Authorization", "Lifecycle", "Security Best Practices", "Transports", "Cancellation", "Ping", "Progress", "Elicitation", "Roots", "Sampling", "Specification", "Overview", "Prompts", "Resources", "Tools", "Completion", "Logging", "Pagination", "Versioning", ]) .describe( "Select a specific section of the MCP specification to retrieve." ), }), execute: async (args) => { const fuse = loadAndIndexDocument(); try { if (!fuse) { throw new UserError("Search index not initialized. Please try again."); } // Find exact section match const matchingChunk = documentChunks.find( (chunk) => chunk.section === args.query ); if (!matchingChunk) { return `No section found with the name "${args.query}".`; } return JSON.stringify( { content: matchingChunk.content, }, null, 2 ); } catch (error) { return `Search error: ${ error instanceof Error ? error.message : "Unknown error" }`; } }, });
- src/index.ts:27-94 (helper)Helper function to load, parse, and index the MCP spec Markdown document into searchable chunks using Fuse.js. Called by handler to ensure index is ready.function loadAndIndexDocument(): Fuse<(typeof documentChunks)[0]> | undefined { try { const docPath = join(__dirname, "../src/lib/llms-full.md"); const content = readFileSync(docPath, "utf-8"); const lines = content.split("\n"); let currentSection = "Overview"; let chunkId = 0; let chunkContent = ""; let chunkStartLine = 1; for (let i = 0; i < lines.length; i++) { const line = lines[i]; if (line.match(/^# /)) { if (chunkContent.trim()) { documentChunks.push({ id: chunkId, content: chunkContent.trim(), section: currentSection, line: chunkStartLine, }); chunkId++; } currentSection = line.replace(/^#+\s*/, ""); chunkContent = line + "\n"; chunkStartLine = i + 1; } else { chunkContent += line + "\n"; // Create chunks of reasonable size (~500 lines) if (chunkContent.split("\n").length > 500) { documentChunks.push({ id: chunkId, content: chunkContent.trim(), section: currentSection, line: chunkStartLine, }); chunkId++; chunkContent = ""; chunkStartLine = i + 1; } } } // Add final chunk if (chunkContent.trim()) { documentChunks.push({ id: chunkId, content: chunkContent.trim(), section: currentSection, line: chunkStartLine, }); } // Initialize Fuse.js search fuse = new Fuse(documentChunks, { keys: ["content", "section"], threshold: 0.3, includeScore: true, }); return fuse; } catch (error) { console.error("Failed to load document:", error); } }