A Model Context Protocol (MCP) server that helps AI assistants like Copilot or Claude analyze code by looking up function usage within source files.
- Function Lookup: Find where and how specific functions are used in your codebase
- Supports Python and TypeScript/TSX files
- Built with the official MCP SDK for standardized protocol support
- Uses regex pattern matching for reliable function search
-
Clone this repository:
git clone <repository-url from this repository> cd MCP_OA
-
Install dependencies:
npm install --legacy-peer-deps
Note: The
--legacy-peer-deps
flag is required to handle dependency conflicts between packages.
Build the TypeScript code:
npm run build
This compiles the source code to the dist
directory.
- Open VS Code settings
- Search for "MCP" or "Model Context Protocol"
- Add a new server with these settings:
- Server Name:
function-lookup
(or any name you prefer) - Command:
node
- Arguments:
dist/src/index.js
(path to the compiled dist/src/index.js on your machine) - Environment Variables: None needed
- Server Name:
- Open Claude or User settings in VS Code
- Navigate to the "MCP Servers" section
- Add a new server with:
{ "mcpServers": { "function-lookup": { "command": "node", "args": ["dist/src/index.js"] } } }
This tool finds occurrences of a specific function within a source file.
Parameters:
functionName
: The name of the function to look forfilePath
: Path to the file to analyze
Example prompt:
Please find where the 'calculate_sum' function is used in src/calculator.py.
The server uses regex pattern matching to find function occurrences in files. The implementation is:
- Reads the specified file
- Uses a regular expression to find all occurrences of the function name as a word boundary
- Returns the line numbers where the function is found
- Handles errors gracefully with appropriate messages
The project includes a comprehensive test suite in the tests
directory.
To run the tests:
-
Build the project:
npm run build
-
Run the test client:
npm run test
The test client will:
- Connect to the MCP server
- List available tools
- Run a series of test cases against the
functionLookup
tool:- Finding functions in the main source code
- Finding functions in test sample files
- Testing with non-existent functions
- Display detailed results for each test case
- Show a test summary at the end
tests/test-client.ts
: The main test runner that connects to the server and runs test casestests/sample.ts
: A sample file with multiple functions for testing the lookup functionality
You should see output showing the lines where different functions are found in the specified files and a summary of passed/failed tests.
You can also test the server by running it directly (note that this will run the server to allow manual testing):
npm run start
And then connect to it using any MCP-compatible client.
If you encounter connection issues with the MCP server:
- Make sure you're using the correct path to the compiled script (
dist/src/index.js
) - Check that all dependencies are installed correctly
- Look for detailed error messages in the server logs
- If you see protocol version errors, make sure your client is compatible with the MCP server