MCP Code Assistant
A minimal Model Context Protocol (MCP) server implementation in Python that provides developer tools for file operations, C code compilation, and executable execution.
A learning project for understanding how to build MCP servers from scratch. Designed with an extensible architecture for future enhancements.
Overview
This MCP server communicates using JSON-RPC 2.0 over stdin/stdout, making it compatible with MCP clients and AI assistants that support the Model Context Protocol.
Features
File Operations
read_file: Read contents from any file on the filesystemwrite_file: Write contents to files (with automatic directory creation)
Future Tools (extensible architecture)
Compile C code
Run executables
Debug tools
Project Structure
Requirements
Python 3.7 or higher
No external dependencies (uses only Python standard library)
Installation
Clone or download this project
No installation needed - uses only stdlib
Usage
Running the Server
The server reads JSON-RPC requests from stdin and writes responses to stdout:
Testing the Server
You can test the server manually by sending JSON-RPC requests via stdin:
Using with MCP Clients
Configure your MCP client to run this server. Example configuration:
Available Tools
read_file
Reads the contents of a file from the filesystem.
Parameters:
path(string, required): Path to the file (absolute or relative)
Example:
write_file
Writes contents to a file on the filesystem. Creates parent directories if needed.
Parameters:
path(string, required): Path to the filecontents(string, required): Contents to write
Example:
Development
Adding New Tools
Create a new file in
tools/(e.g.,compile_ops.py)Define your tool handler functions
Create a
TOOLSdictionary with tool definitionsImport and register in
tools/__init__.py
Example tool structure:
Logging
All logs go to stderr to keep stdout clean for JSON-RPC communication. Use the logger module:
Protocol Support
Protocol Version: 2024-11-05
JSON-RPC: 2.0
Methods Supported:
initialize: Initialize the server connectiontools/list: List all available toolstools/call: Execute a tool
License
This is a minimal educational implementation. Use and modify as needed.
Future Enhancements
C code compilation tool (
compile_c)Execute binary tool (
run_executable)Debugging tools
Code analysis tools
Git integration
Project scaffolding tools
This server cannot be installed