@ubuligan/codegen
v0.1.1
Published
Generate a type-safe TypeScript SDK from a live MCP server's tool/resource/prompt schemas
Downloads
24
Maintainers
Readme
@ubuligan/codegen
Introspect a live MCP server and generate a type-safe TypeScript SDK from its tool, resource and prompt schemas. One typed class, one method per tool, with argument and result types derived from the server's JSON Schemas.
Part of the MCP Toolkit. Ships the mcp-codegen CLI.
CLI
No install needed:
# From an HTTP server:
npx @ubuligan/codegen http://localhost:3000/mcp -o src/mcp-sdk.ts
# From a local stdio server (the command to spawn it):
npx @ubuligan/codegen "node dist/index.js" -o src/mcp-sdk.ts| Flag | Default | Purpose |
| --- | --- | --- |
| <target> | — | Server URL (http://…) or a stdio command line. |
| -o, --out <file> | mcp-sdk.ts | Output file. |
| -c, --class-name <name> | GeneratedMCPClient | Name of the generated class. |
| --stdout | off | Print to stdout instead of writing a file. |
The generated SDK imports from @ubuligan/client,
so install that in the consuming project:
npm install @ubuligan/clientimport { GeneratedMCPClient } from "./mcp-sdk.js";
const sdk = new GeneratedMCPClient({ transport: { type: "http", url: "http://localhost:3000/mcp" } });
await sdk.connect();
const sum = await sdk.add({ a: 2, b: 3 }); // fully typedProgrammatic API
npm install @ubuligan/codegenimport { generateSdk } from "@ubuligan/codegen";
const { code, introspection } = await generateSdk({
target: "http://localhost:3000/mcp",
className: "MyClient",
});
console.log(`${introspection.tools.length} tools`);
// write `code` wherever you likegenerateSdk({ target, className?, ... })→{ code, introspection }introspect(target)→ rawIntrospection(tools/resources/prompts).parseTarget(string)→ aTarget(url vs stdio command).emitSdk(introspection, opts)→ SDK source string.
License
MIT
