@chttp/mcp
v0.5.0
Published
Model Context Protocol server (JSON-RPC 2.0) mounted as a chttp route, authored inside the scriptc compilable subset
Maintainers
Readme
@chttp/mcp
Model Context Protocol server (JSON-RPC 2.0, spec revision 2025-06-18) authored in the scriptc-compilable subset — the same source type-checks to a JS package and lowers into a native ELF with scriptc build. Zero runtime dependencies. Validation flows through the Standard Schema seam, so @chttp/val, valibot, zod, or any conforming validator works; JSON Schema emission flows through a tiny adapter you inject.
import { Server, StreamableHttpTransport, tool } from "@chttp/mcp";
import * as v from "@chttp/val";
const server = new Server({
name: "todo-mcp",
version: "0.1.0",
emitJsonSchema: (s) => v.toJsonSchema(s), // adapter seam — see docs/schema.md
});
tool(
server,
"add_todo",
v.object({ text: v.pipe(v.string(), v.minLength(1)) }),
async (input) => `added: ${input.text}`,
);
export default {
fetch: StreamableHttpTransport.route(server), // (req) => Promise<Response>
};What ships
Server—tool/resource/promptregistration +handleRequest(JsonRpcRequest): Promise<JsonRpcResponse | null>covering the full method table (initialize,ping,tools/list,tools/call,resources/list,resources/read,resources/templates/list,prompts/list,prompts/get,notifications/*,logging/setLevel,completion/complete).StreamableHttpTransport— POST request/response + SSEGET ?stream=progressfornotifications/progress, on theRequest/Responsesurface.Mcp-Session-Idis set-but-unused in v1.- The auto-wrap ladder for tool returns (string → text block,
ContentBlock/ContentBlock[]/CallToolResultpassthrough, plain object → dual content,null→ empty, throw →isError). encodeSseEvent/encodeSseComment/encodeSseRetry, envelope helpers (parseBody,parseRequest,resultResponse,errorResponse,errorFor,notification), progress/log notification builders,runStdValidate/validatorFor.@chttp/mcp/client— a typed client on the./clientsubpath:Client+toolDef/resourceDef/promptDefschema descriptors shared with server registration (server.toolDef(def, handler)), overFetchClientTransport, anode:net/node:tlsHTTP/1.1+SSE transport for the ELF path, andStdioClientTransport(Node-only). See docs/client.md.
Docs: docs/ — integration, schema seams, transport, streamable-http coverage, auto-wrap, scriptc subset notes. Stdio wiring example: examples/integrations/mcp-stdio/.
Testing
pnpm --filter @chttp/mcp test # node:test against the tsc build
bash packages/mcp/test/elf.test.sh # scriptc build + native smoke