Skip to main content
For the TypeScript examples, use the TypeScript setup, including "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.
MCP tool names combine the sanitized server and tool names, such as 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 in MCP_URL. Set MCP_TOKEN only if that service expects bearer authentication. The endpoint must be reachable from the runtime host.
Use 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 to sdkMcpServers on an Agent; it is configuration, not a standalone server implementation.
All paths and executables resolve on the runtime host. The runtime owns the subprocess and closes its session MCP scope. With an isolated runtime, pass required environment values explicitly; do not assume the subprocess sees your shell configuration.

Resources and prompts

SDK HTTP hosting additionally accepts resources and prompts. This example registers a resource and a prompt without making a model request:
A separate MCP client can list/read resources and fetch prompts from the hosted endpoint while its session is alive. Required prompt arguments and duplicate names/URIs are checked. Direct transport supports tools only and rejects resource/prompt registrations. Session MCP registration supplies tools to the agent loop. It does not automatically insert resource contents into model context, turn MCP prompts into slash commands, or add 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.