"type": "module" and the tsx runner.
MCP connects the runtime to tools supplied by your application or another service. Start with a direct SDK-hosted tool when the function already lives in your JavaScript process. Use an external MCP descriptor for a service or subprocess you operate separately.
Run an SDK-hosted tool
Use the quickstart setup with Node.js 22+,cognitio-agent-sdk and OPENAI_API_KEY. Save this as mcp.ts; run node --env-file=.env --import tsx mcp.ts.
diagnostics_ping. This differs from Agent.tools, whose tools use sdk_<name>. Choose unique names after sanitization. For tools with arguments, validate inside execute before side effects; the schema advertises inputs but does not automatically parse callback arguments. See tools.
createSdkMcpServer() returns a descriptor. The SDK starts hosting when a session registers it, and closes the hosted resources with their owner. Choose direct explicitly for remote runtimes; omitting transport uses HTTP hosting.
Connect an external service
The following complete connection example requires an existing MCP endpoint inMCP_URL. Set MCP_TOKEN only if that service expects bearer authentication. The endpoint must be reachable from the runtime host.
transport: "sse" for a legacy SSE endpoint. Omitting transport tries Streamable HTTP with SSE fallback. Session descriptors support explicit headers and oauth: false; they do not start an interactive OAuth login. Tool permissions still apply after connection.
Run an external subprocess
This descriptor assumes you already have an MCP server script. Add it tosdkMcpServers on an Agent; it is configuration, not a standalone server implementation.
Resources and prompts
SDK HTTP hosting additionally acceptsresources and prompts. This example registers a resource and a prompt without making a model request:
Session.readResource()/getPrompt() methods. For explicit agent context, read the content in your application and pass it in a prompt. For slash commands, use programmatic commands.