The File Context Server is a powerful Model Context Protocol (MCP) server that provides file system access capabilities to Large Language Models (LLMs). It enables models to read, search, and analyze code files with advanced features like real-time file watching and intelligent caching.
Install the File Context Server automatically using Smithery:
npx -y @smithery/cli install @bsmi021/mcp-file-context-server --client claude
Install using npm:
npm install @modelcontextprotocol/file-context-server
Launch the server with:
npx file-context-server
Use the list_context_files
tool to get file information:
{
"path": "./src",
"recursive": true,
"includeHidden": false
}
Read file or directory contents with the read_context
tool:
{
"path": "./src/index.ts",
"encoding": "utf8",
"maxSize": 1000000,
"recursive": true,
"fileTypes": ["ts", "js"]
}
Search for patterns in files using search_context
:
{
"pattern": "function.*",
"path": "./src",
"options": {
"recursive": true,
"contextLines": 2,
"fileTypes": ["ts"]
}
}
Get code quality metrics with analyze_code
:
{
"path": "./src",
"recursive": true,
"metrics": ["complexity", "dependencies", "quality"]
}
Monitor cache performance using cache_stats
:
{
"detailed": true
}
The server provides specific error codes for different situations:
FILE_NOT_FOUND
: File or directory doesn't existPERMISSION_DENIED
: Access permission issuesINVALID_PATH
: Invalid file path formatFILE_TOO_LARGE
: File exceeds size limitENCODING_ERROR
: File encoding issuesUNKNOWN_ERROR
: Unexpected errorsCustomize server behavior with these environment variables:
MAX_CACHE_SIZE
: Maximum number of cached entries (default: 1000)CACHE_TTL
: Cache time-to-live in milliseconds (default: 1 hour)MAX_FILE_SIZE
: Maximum file size in bytes for readingThere are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.