Skip to content

feat: MCP server with management tools + SSE transport#28

Merged
christianromeni merged 2 commits intomainfrom
feat/mcp-server
Mar 27, 2026
Merged

feat: MCP server with management tools + SSE transport#28
christianromeni merged 2 commits intomainfrom
feat/mcp-server

Conversation

@christianromeni
Copy link
Copy Markdown
Contributor

Summary

Adds a Model Context Protocol (MCP) server to VoidLLM for IDE integration. Claude Code, Cursor, and Windsurf can manage VoidLLM directly via MCP tools.

MCP Server

  • JSON-RPC 2.0 protocol over Streamable HTTP (spec version 2025-03-26)
  • 6 tools: list_models, get_model_health, get_usage, list_keys, create_key, list_deployments
  • All tools fully implemented against real DB — no stubs
  • RBAC-scoped: member sees name+type, admin sees full model info
  • Internal errors sanitized (no DB details leaked to client)
  • Audit middleware excludes MCP (tool calls not auditable)

SSE Transport

  • POST with Accept: text/event-stream → SSE-wrapped response
  • GET opens SSE stream (endpoint event + 30s keep-alive pings)
  • 10 minute stream deadline prevents DoS
  • Proper Accept header parsing

Privacy

  • Tool call arguments and results NOT logged
  • Consistent with zero-knowledge proxy architecture

Docs

  • README: MCP Integration section with setup guide
  • configuration.md: full MCP server documentation
  • Landing page (EN + DE): MCP in community feature list

Test plan

  • go test ./... -race — 19 packages, 91+ MCP tests
  • npx tsc --noEmit && npm run lint
  • Add to .mcp.json → tools appear in Claude Code
  • list_models via MCP → returns models with health
  • SSE POST with Accept header → event-stream response
  • GET SSE stream → endpoint event + pings
  • Unauthenticated → 401

Implements an MCP (Model Context Protocol) server at /api/v1/mcp/voidllm
exposing VoidLLM management capabilities as tools for IDE integration
(Claude Code, Cursor, Windsurf).

Protocol: JSON-RPC 2.0 over Streamable HTTP. No external MCP library —
implemented directly on Fiber for full control, performance, and privacy.

Tools:
- list_models — RBAC-scoped: admin sees full info (strategy, deployments),
  member sees only name + type
- get_model_health — per-model/deployment health status
- get_usage — usage stats scoped to caller's key/org
- list_keys — API keys visible to caller (own for member, all for admin)
- create_key — create temporary API key with optional expiry
- list_deployments — deployment details (system_admin only)

All tools fully implemented against real DB — no stubs.

Security:
- Auth via existing Bearer token middleware
- RBAC checks per tool matching REST API permissions
- Internal errors sanitized ("internal error", no DB details leaked)
- Audit middleware excludes MCP (tool calls are not auditable mutations)
- Defensive body copy (fasthttp buffer recycling safe)
- MCP spec-compliant notification handling

Tests: 91 MCP tests — protocol, server, tool implementations, RBAC,
integration, error sanitization, concurrency.
- POST Accept: text/event-stream wraps JSON-RPC response in SSE format
- GET /mcp/voidllm opens SSE stream (endpoint event + 30s keep-alive)
- 10 minute stream deadline prevents DoS via connection exhaustion
- Proper Accept header parsing (comma-separated, quality params)
- README: MCP Integration section with setup guide + tool reference
- configuration.md: MCP server docs (endpoints, tools, RBAC, privacy)
- Landing page (EN + DE): MCP server in community feature list
- 7 SSE transport tests (POST+GET, auth, headers, notifications)
@christianromeni christianromeni merged commit bd08768 into main Mar 27, 2026
5 checks passed
@christianromeni christianromeni deleted the feat/mcp-server branch March 27, 2026 20:53
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 65.59140% with 160 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/app/app.go 0.00% 138 Missing ⚠️
internal/api/admin/mcp_handler.go 77.77% 7 Missing and 5 partials ⚠️
internal/mcp/voidllm.go 95.53% 5 Missing and 3 partials ⚠️
internal/audit/middleware.go 0.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant