defineSource() entry point from @toolshed/sdk.
Namespaces
Every source requires anamespace. Toolshed prepends that namespace to every tool path the source generates. A billing API with a GET /invoices/list endpoint under namespace "billing" becomes billing.invoices.list in the registry.
Namespaces must be a single lowercase identifier. They allow policy patterns like billing.** to grant or restrict access to all tools from that source without naming tools individually.
Source types
OpenAPI
The OpenAPI adapter fetches a JSON or YAML spec, parses every operation, and generates one tool per endpoint. GET/HEAD/OPTIONS operations are treated as read-only; POST/PUT/PATCH/DELETE are markeddestructive: true and will trigger elicitation before execution.
operationFilter to exclude endpoints you don’t want exposed as tools:
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique source identifier |
namespace | string | Yes | Tool path prefix |
specUrl | string | Yes | URL to the OpenAPI JSON or YAML spec |
auth | SourceAuth | No | Auth for outbound API calls |
baseUrl | string | No | Override the base URL from servers[0] in the spec |
operationFilter | function | No | Return true to include an operation |
MCP
The MCP adapter connects to an existing MCP server and proxies its tools into your registry. Use this to incorporate third-party MCP servers without rewriting them as Toolshed plugins.| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique source identifier |
namespace | string | Yes | Tool path prefix |
transport | object | Yes | How to connect: http (URL + headers) or stdio (command + args + env) |
auth | SourceAuth | No | Auth for the MCP server connection itself |
GraphQL
The GraphQL adapter introspects a schema and generates one tool per query and one tool per mutation. Queries are treated as read-only; mutations are markeddestructive: true.
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique source identifier |
namespace | string | Yes | Tool path prefix |
endpoint | string | Yes | GraphQL endpoint URL |
auth | SourceAuth | No | Auth for outbound GraphQL calls |
headers | Record<string, string> | No | Extra headers for introspection and tool calls |
operationFilter | function | No | Return true to include an operation |
Plugin
The plugin source type wraps an existingdefinePlugin() result so it integrates into the same source registration flow as OpenAPI and GraphQL sources. Use this when you want to register a hand-written plugin through the registry API rather than bundling it directly into the server.
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique source identifier |
namespace | string | Yes | Tool path prefix |
pluginId | string | Yes | The id of the definePlugin() result to wrap |
Source authentication
All source types exceptplugin accept an auth field that controls how the adapter authenticates outbound requests to the upstream API.
oauth2
oauth2
Delegates token acquisition to a named OAuth2 provider. Scopes are optional and can refine what the token grants.
api_key
api_key
Reads a key from an environment variable and sends it in a named request header.
bearer
bearer
Reads a token from an environment variable and sends it as
Authorization: Bearer <token>.none
none
No authentication. Use for public APIs or APIs where auth is handled by a proxy layer.
Registering a source via the API
Once you have adefineSource() config, register it by sending it to POST /api/registry/sources. Toolshed resolves the source, generates its tools, and adds them to the catalog immediately.
The
operationFilter field is a function and cannot be serialized to JSON. If you need filtering, configure it in code using defineSource() and register the source programmatically rather than via the REST API.