Skip to main content

MCP server that indexes a codebase's public API at startup and serves it via compact tool responses. Pluggable parsers for C#, Go, Java, TypeScript, Python, and more.

Project description

codesurface

PyPI Version PyPI Downloads MCP Registry License: MIT Python 3.10+ Blog Post

MCP server that indexes your codebase's public API at startup and serves it via compact tool responses — saving tokens vs reading source files.

Parses source files, extracts public classes/methods/properties/fields/events, and serves them through 5 MCP tools. Works with Claude Code, Cursor, Windsurf, or any MCP-compatible AI tool.

Supported languages: C# (.cs), Go (.go), Java (.java), Python (.py), TypeScript/TSX (.ts, .tsx)

Quick Start

pip install codesurface

Then add to your .mcp.json:

{
  "mcpServers": {
    "codesurface": {
      "command": "codesurface",
      "args": ["--project", "/path/to/your/src"]
    }
  }
}

Point --project at any directory containing supported source files — a Unity Assets/Scripts folder, a Spring Boot project, a .NET src/ tree, a Node.js/React project, a Python package, etc. Languages are auto-detected.

Restart your AI tool and ask: "What methods does MyService have?"

CLAUDE.md Snippet

Add this to your project's CLAUDE.md (or equivalent instructions file). This step is important. Without it, the AI has the tools but won't know when to reach for them.

## Codebase API Lookup (codesurface MCP)

Use codesurface MCP tools BEFORE Grep, Glob, Read, or Task (subagents) for any class/method/field lookup. This applies to you AND any subagents you spawn.

| Tool | Use when | Example |
|------|----------|---------|
| `search` | Find APIs by keyword | `search("MergeService")` |
| `get_signature` | Need exact signature | `get_signature("TryMerge")` |
| `get_class` | See all members on a class | `get_class("BlastBoardModel")` |
| `get_stats` | Codebase overview | `get_stats()` |

Every result includes file path + line numbers. Use them for targeted reads:
- `File: Service.cs:32``Read("Service.cs", offset=32, limit=15)`
- `File: Converter.java:504-506``Read("Converter.java", offset=504, limit=10)`

Never read a full file when you have a line number. Only fall back to Grep/Read for implementation details (method bodies, control flow).

Tools

Tool Purpose Example
search Find APIs by keyword "MergeService", "BlastBoard", "GridCoord"
get_signature Exact signature by name or FQN "TryMerge", "CampGame.Services.IMergeService.TryMerge"
get_class Full class reference card — all public members "BlastBoardModel" → all methods/fields/properties
get_stats Overview of indexed codebase File count, record counts, namespace breakdown
reindex Incremental index update (mtime-based) Only re-parses changed/new/deleted files. Also runs automatically on query misses

Tested On

Project Language Files Records Time
vscode TypeScript 6,611 88,293 9.3s
Paper Java 2,909 33,973 2.3s
client-go Go 219 2,760 0.4s
langchain Python 1,880 12,418 1.1s
pydantic Python 365 9,648 0.3s
guava Java 891 8,377 2.4s
immich TypeScript 919 7,957 0.6s
fastapi Python 881 5,713 0.5s
ant-design TypeScript 2,947 5,452 0.9s
dify TypeScript 4,903 5,038 1.9s
crawlee-python Python 386 2,473 0.3s
flask Python 63 872 <0.1s
cobra Go 15 249 <0.1s
gin Go 41 574 <0.1s
Unity game (private) C# 129 1,018 0.1s

Line Numbers for Targeted Reads

Every record includes line_start and line_end (1-indexed). Multi-line declarations span the full signature:

[METHOD] com.google.common.base.Converter.from
  Signature: static Converter<A, B> from(Function<...> forward, Function<...> backward)
  File: Converter.java:504-506          ← multi-line signature

[METHOD] server.AlbumController.createAlbum
  Signature: createAlbum(@Auth() auth: AuthDto, @Body() dto: CreateAlbumDto)
  File: album.controller.ts:46          ← single-line

This lets AI agents do targeted reads instead of reading full files:

# Instead of reading the entire 600-line file:
Read("Converter.java")                     # 600 lines, ~12k tokens

# Read just the method + context:
Read("Converter.java", offset=504, limit=10)  # 10 lines, ~200 tokens

Benchmarks

Measured against a real Unity game project (129 files, 1,018 API records) across a 10-step cross-cutting research workflow.

Strategy Total Tokens vs MCP
MCP (codesurface) 1,021
Skilled Agent (Grep + partial Read) 4,453 4.4x more
Naive Agent (Grep + full Read) 11,825 11.6x more

Even with follow-up reads for implementation detail, the hybrid MCP + targeted Read approach uses 54% fewer tokens than a skilled Grep+Read agent.

See workflow-benchmark.md for the full step-by-step analysis.

Setup Details

Claude Code configuration

Add to <project>/.mcp.json:

Using uv (recommended):

{
  "mcpServers": {
    "codesurface": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/codesurface", "codesurface", "--project", "/path/to/your/src"]
    }
  }
}

Using pip install:

{
  "mcpServers": {
    "codesurface": {
      "command": "codesurface",
      "args": ["--project", "/path/to/your/src"]
    }
  }
}
Project structure
codesurface/
├── src/codesurface/
│   ├── server.py           # MCP server — 5 tools
│   ├── db.py               # SQLite + FTS5 database layer
│   └── parsers/
│       ├── base.py         # BaseParser ABC
│       ├── csharp.py       # C# parser
│       ├── go.py           # Go parser
│       ├── java.py         # Java parser
│       ├── python_parser.py # Python parser
│       └── typescript.py   # TypeScript/TSX parser
├── pyproject.toml
└── README.md
Troubleshooting

"No codebase indexed"

  • Ensure --project points to a directory containing supported source files (.cs, .go, .java, .py, .ts, .tsx)
  • The server indexes at startup — check stderr for the "Indexed N records" message

Server won't start

  • Check Python version: python --version (needs 3.10+)
  • Check mcp[cli] is installed: pip install mcp[cli]

Stale results after editing source files

  • The index auto-refreshes on query misses — if you add a new class and query it, the server reindexes and retries automatically
  • You can also call reindex() manually to force an incremental update

Contact

fuatcankoseoglu@gmail.com

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codesurface-0.7.0.tar.gz (52.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codesurface-0.7.0-py3-none-any.whl (51.7 kB view details)

Uploaded Python 3

File details

Details for the file codesurface-0.7.0.tar.gz.

File metadata

  • Download URL: codesurface-0.7.0.tar.gz
  • Upload date:
  • Size: 52.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codesurface-0.7.0.tar.gz
Algorithm Hash digest
SHA256 60c9e7347261084626fcbbb4faf2ec3101cf0a6262de68c86b9ac69af7ee1a75
MD5 8424ab8636af94e7327d169b30de1583
BLAKE2b-256 f635f9ac9cf4f8bb74be8178b5569719397441dfd377212f1e62830910f1408e

See more details on using hashes here.

Provenance

The following attestation bundles were made for codesurface-0.7.0.tar.gz:

Publisher: publish.yml on Codeturion/codesurface

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codesurface-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: codesurface-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 51.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codesurface-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1ce145745c7bac242cc04a711f12e0c1a57f7c854330f20f8cbe825de068929
MD5 ba658a07c085b22f157a87dee09d8932
BLAKE2b-256 9d583eba61e0a01104c711e3590e469cbd0bd73e99b5f48d85afb32590cafb5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for codesurface-0.7.0-py3-none-any.whl:

Publisher: publish.yml on Codeturion/codesurface

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page