mcp-documentation-server
Copilot instructions342 starsChanged 18 months agoMITView on GitHub
This is a TypeScript-based Model Context Protocol (MCP) server providing document management and semantic search capabilities using local AI embeddings. Key architectural patterns:
- Reads credentials
In this repositoryOne other file it gives its agents.
- documentation-serverSkill
The file
We split this copilot-instructions.md into the rules it gives an agent
6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 9
Local-First Storage: All data stored in ~/.mcp-documentation-server/ (no database required)
- Distinctive: line 69
All tools follow this structure:
- Very specific: line 85
Default paths always use getDefaultDataDir() from utils.ts
- Distinctive: line 104
Document storage with searchable chunks
- Very specific: line 108
Tool Testing: Use npm run inspect for interactive web UI
- Distinctive: line 110
Error Debugging: Check document existence before search operations
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MCP Documentation Server - AI Coding Agent Instructions
Architecture Overview
This is a TypeScript-based Model Context Protocol (MCP) server providing document management and semantic search capabilities using local AI embeddings. Key architectural patterns:
- FastMCP Framework: Uses
fastmcplibrary for MCP server implementation with Zod schema validation - Modular Design: Core functionality split across
DocumentManager,EmbeddingProvider, and utility modules - Local-First Storage: All data stored in
~/.mcp-documentation-server/(no database required) - Lazy Loading: Embedding models load on-demand to avoid startup delays
- Chunk-Based Search: Documents split into chunks with embeddings for granular semantic search
Core Components
Server Entry Point (src/server.ts)
- Main FastMCP server with 8 MCP tools (add_document, search_documents, etc.)
- Uses
#!/usr/bin/env nodeshebang - this file becomes the CLI executable - Environment configuration via
dotenv(loads.envfiles) - Singleton
DocumentManagerinstance with lazy initialization
Document Management (src/document-manager.ts logic in server.ts)
- Chunking Strategy: Text split into ~500-character chunks with overlap for better search
- ID Generation: Uses timestamp + random suffix pattern (see
generateId()) - Storage: JSON files per document in
data/directory - File Processing: Supports .txt, .md, .pdf via uploads folder workflow
Embedding Providers (src/embedding-provider.ts)
- Primary:
TransformersEmbeddingProviderusing@xenova/transformers(local ML) - Fallback:
SimpleEmbeddingProvider(hash-based, no ML dependencies) - Model Selection: Via
MCP_EMBEDDING_MODELenv var (default:Xenova/all-MiniLM-L6-v2) - Critical: Model downloads (~420MB) on first use - implement timeouts
Development Workflows
Build & Run Commands
npm run build # TypeScript compilation + executable permissions (shx chmod)
npm start # Direct tsx execution (development)
npm run dev # FastMCP dev mode with hot reload
npm run inspect # FastMCP web UI for tool testingPackage Distribution
- Binary:
dist/server.jsbecomes CLI executable viapackage.jsonbin field - NPX Usage:
npx @andrea9293/mcp-documentation-server(primary distribution method) - Publishing: Automated via semantic-release with GitHub Actions
Development Setup
npm run dev # Hot reload during development
npm run inspect # Visual tool testing interfaceProject-Specific Patterns
Error Handling Convention
- Tools return descriptive error messages via
throw new Error() - Embedding failures gracefully fallback to SimpleEmbeddingProvider
- File operations include existence checks before processing
Data Directory Structure
~/.mcp-documentation-server/
├── data/ # JSON files per document (${id}.json)
└── uploads/ # User drops files here for processingMCP Tool Patterns
All tools follow this structure:
server.addTool({
name: "tool_name",
description: "Tool description",
parameters: z.object({...}), // Zod validation
execute: async (args) => { // Returns string or throws Error
const manager = await initializeDocumentManager();
// ... implementation
}
});Environment Configuration
MCP_EMBEDDING_MODEL: Embedding model selection (affects all new documents)dotenv/configimport at top of server.ts enables .env file support- Default paths always use
getDefaultDataDir()from utils.ts
Integration Points
FastMCP Integration
- Server definition:
new FastMCP({ name, version }) - Tool registration:
server.addTool()with Zod schemas - Automatic MCP protocol handling (stdio communication)
Embeddings Pipeline
- Async Initialization: Models load lazily on first embedding request
- Timeout Handling: 5-minute timeout for model downloads
- Memory Management: Single pipeline instance per provider
File Processing Workflow
- User places files in uploads/ (via
get_uploads_pathtool) process_uploadstool discovers .txt/.md/.pdf files- Content extraction (including PDF via
pdf-ts) - Automatic chunking and embedding generation
- Document storage with searchable chunks
Testing & Debugging
- Tool Testing: Use
npm run inspectfor interactive web UI - Log Output: Embedding initialization logs to stderr (not stdout - preserves MCP protocol)
- Error Debugging: Check document existence before search operations
- Performance: First embedding takes time (model download), subsequent ones are fast
Critical Implementation Notes
- Never output to stdout in the server (breaks MCP protocol) - use stderr for logs
- Embedding Model Changes: Require re-adding all documents (incompatible embeddings)
- File Permissions: Build process sets executable permissions on dist/*.js
- TypeScript: Uses ES modules (
"type": "module") with .js imports for compiled output
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

