Skip to content

MCP server HTTP mode with per-request auth#2

Open
chrisaddams wants to merge 1 commit intomainfrom
feat/mcp-http-mode-public
Open

MCP server HTTP mode with per-request auth#2
chrisaddams wants to merge 1 commit intomainfrom
feat/mcp-http-mode-public

Conversation

@chrisaddams
Copy link
Copy Markdown
Contributor

Summary

  • HTTP transport mode for the MCP server, enabling the AI sidebar to execute tools via HTTP instead of stdio
  • Per-request credential isolation using AsyncLocal — no shared auth state between concurrent requests
  • Security hardening for multi-tenant hosted environments
  • 40 unit tests covering security validation, credential isolation, tool registry, and blocked tools

Key Changes

  • mcp/Program.cs — HTTP server with health check, tool listing, and authenticated tool execution endpoints
  • mcp/McpClientFactory.cs — Per-request credential management with JWT expiry checking and token refresh
  • mcp/Tools/CliTool.cs — Expanded tool set (entities, fields, workflows, data, fetch) with SafeArgs input validation
  • mcp/McpToolRegistry.cs — Tool definition registry for HTTP mode
  • tests-mcp/ — 40 unit tests

Security

  • Authorization header + X-Org-Id + X-Instance-Url required on all tool execution requests
  • Credential-mutating tools blocked in HTTP mode (login, logout, config_use, etc.)
  • Request body size limited to 1MB
  • CORS origins configurable via MCP_CORS_ORIGINS (defaults to localhost for dev)
  • SafeArgs regex whitelist on all command inputs
  • Tool results truncated to 500 chars in server logs
  • Generic error responses to clients, full details logged server-side only

Running

cd mcp
dotnet run -- --http --port 5299

Environment variables:

  • MCP_CORS_ORIGINS — comma-separated allowed origins (default: http://localhost:5200)

Test plan

  • 40/40 MCP unit tests passing
  • Health endpoint returns 200 at /health
  • Tool listing returns available tools at /tools
  • Tool execution requires Authorization header (401 without)
  • Credential-mutating tools return 403 in HTTP mode
  • CORS headers present for configured origins
  • Concurrent requests maintain credential isolation

Add HTTP transport mode alongside stdio for hosting the MCP server as a
web service. The AI sidebar connects to this server for tool execution.

- Per-request credential isolation via AsyncLocal (no shared state)
- Authorization header + X-Org-Id + X-Instance-Url required on tool calls
- Credential-mutating tools blocked in HTTP mode (login, logout, etc.)
- Request body size limited to 1MB
- CORS origins configurable via MCP_CORS_ORIGINS env var
- Tool results truncated to 500 chars in logs
- Generic error messages to clients, details logged server-side
- SafeArgs regex whitelist on all command inputs
- Token refresh with JWT expiry checking
- 40 unit tests covering security, isolation, registry, and blocked tools

// ── HTTP mode: in-process execution ──────────────────────────────────

private async Task<string> ExecuteInProcess(string command)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an easier way to handle all of these permutations of commands and options? I feel like we might be duplicating it here and in the CLI

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.

2 participants