Skip to content

Add MCP server support to agentlang runtime#619

Open
fractlrao wants to merge 4 commits intomainfrom
mcp-extension-to-http-server
Open

Add MCP server support to agentlang runtime#619
fractlrao wants to merge 4 commits intomainfrom
mcp-extension-to-http-server

Conversation

@fractlrao
Copy link
Copy Markdown
Contributor

@fractlrao fractlrao commented Feb 19, 2026

Summary

  • MCP server module: Agentlang apps can now act as MCP servers over Streamable HTTP transport, allowing LLM clients to discover and invoke tools/resources. Tools are auto-registered from public events and resources from entities, with per-tool/resource auth checks via shared verifyAuth.
  • Shared API handlers: Extracted common handlers (evaluateEvent, queryEntity, createEntity, updateEntity, deleteEntity, normalizedResult, verifyAuth) from http.ts into handlers.ts for reuse by both the HTTP and MCP layers.
  • MCP config options: Added instructions, stateless, enableJsonResponse, uriScheme, and sessionTtl configuration. Resource templates let clients fetch individual entities by ID via {scheme}://{module}/{entity}/{id}.
  • Stale session cleanup: TTL-based cleanup of idle sessions (default 30 min), skipped in stateless mode. Declared listChanged capability for tools and resources.

Test plan

  • Verify existing HTTP API tests still pass
  • Run new MCP server tests (test/runtime/mcpserver.test.ts) covering tool invocation, resource reads, resource templates, auth, and session management
  • Test with an MCP-compatible LLM client (e.g. Claude Desktop) to confirm tool discovery and invocation end-to-end

Agentlang apps can now act as MCP servers, allowing LLM clients to
discover and invoke tools/resources over Streamable HTTP transport.

- Extract shared API handlers (handlers.ts) from http.ts for reuse
  by both HTTP and MCP layers (evaluateEvent, queryEntity, createEntity,
  updateEntity, deleteEntity, verifyAuth, normalizedResult)
- Add MCP server module (mcp.ts) with tool registration from public
  events, resource registration from entities, per-session transport
  management, and JSON Schema conversion from RecordSchema
- Add MCP config section to ConfigSchema (enabled, path, name, version)
- Add setMcpEndpointsUpdater for dynamic tool/resource updates
- Wire authentication through MCP transport via req.auth -> extra.authInfo
  with per-tool and per-resource auth checks using shared verifyAuth
- Add resource templates (ListResourceTemplates handler) so clients can
  fetch individual entities by ID via {scheme}://{module}/{entity}/{id}
- Extend ReadResource to parse template URIs and query single entities
- Replace hardcoded agentlang:// scheme with configurable uriScheme
  (defaults to app name)
- Add TTL-based stale session cleanup with configurable sessionTtl
  (default 30 min), skipped in stateless mode
- Declare listChanged capability for tools and resources
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