Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
# This job can push tags and publish, so it restores nothing from the shared
# cache, as setup-node advises for privileged workflows.
package-manager-cache: false
scope: '@doist'
scope: '@todoist'
registry-url: 'https://registry.npmjs.org/'

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mcp-core

Shared core for the Doist MCP servers (`@doist/todoist-mcp`, `@doist/comms-mcp`, `@doist/automations-mcp`): the tool contract, tool registration, how a result is shaped for the wire, and contract test suites. TypeScript, ESM-only, Node ≥ 24.
Shared core for the Doist MCP servers (`@todoist/mcp`, `@todoist/comms-mcp`, `@todoist/automations-mcp`): the tool contract, tool registration, how a result is shaped for the wire, and contract test suites. TypeScript, ESM-only, Node ≥ 24.

> For where things are, read [`CODEBASE.md`](./CODEBASE.md). This file covers the _rules_.

Expand Down
14 changes: 7 additions & 7 deletions CODEBASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

## What this project is

`@doist/mcp-core` is a **shared TypeScript library** for the Doist MCP servers
(`@doist/todoist-mcp`, `@doist/comms-mcp`, `@doist/automations-mcp`). It is **not a server**:
`@todoist/mcp-core` is a **shared TypeScript library** for the Doist MCP servers
(`@todoist/mcp`, `@todoist/comms-mcp`, `@todoist/automations-mcp`). It is **not a server**:
it ships the tool contract, a tool registrar with hooks for what differs per product, the
wire shaping of tool results, the contract a server offers its host (token validation and the
factory options), and contract test suites each server runs over its own tools.
Expand Down Expand Up @@ -43,11 +43,11 @@ oxlint + oxfmt · semantic-release.

## Public API surface (`package.json#exports`)

| Subpath | Provides | Peers it needs |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| `.` (root) | The tool types, `createToolRegistrar`, `getToolOutput`, `removeNullFields`, schema cache, annotations | `@modelcontextprotocol/server`, `zod` |
| `@doist/mcp-core/host` | `validateBearerToken`, `TokenValidationError`, the host contract types (`TokenValidationResult`, `ValidateToken`, `McpServerOptions`), and the host's helpers (`isTransientValidationError`, `buildBearerChallenge`, `createTokenVerdictCache`) | none |
| `@doist/mcp-core/testing` | `describeOutputSchemaNullability`, `describeAdvertisedToolSchemas`, `describeToolAnnotations`, `describeTokenFootprint` and the helpers they use | the above; also imports `@modelcontextprotocol/client` and `vitest`, undeclared |
| Subpath | Provides | Peers it needs |
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| `.` (root) | The tool types, `createToolRegistrar`, `getToolOutput`, `removeNullFields`, schema cache, annotations | `@modelcontextprotocol/server`, `zod` |
| `@todoist/mcp-core/host` | `validateBearerToken`, `TokenValidationError`, the host contract types (`TokenValidationResult`, `ValidateToken`, `McpServerOptions`), and the host's helpers (`isTransientValidationError`, `buildBearerChallenge`, `createTokenVerdictCache`) | none |
| `@todoist/mcp-core/testing` | `describeOutputSchemaNullability`, `describeAdvertisedToolSchemas`, `describeToolAnnotations`, `describeTokenFootprint` and the helpers they use | the above; also imports `@modelcontextprotocol/client` and `vitest`, undeclared |

## `src/` tree

Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @doist/mcp-core
# @todoist/mcp-core

Shared core for Todoist's MCP servers ([todoist-mcp](https://github.com/todoist/todoist-mcp), [comms-mcp](https://github.com/todoist/comms-mcp) and the Automations MCP server): the tool contract, tool registration, how a tool result is shaped for the wire, the contract a server offers the host that serves it, and the contract test suites every server runs over its own tools.

Expand All @@ -7,9 +7,11 @@ TypeScript, ESM-only, Node ≥ 24, npm ≥ 11.
## Install

```bash
npm install @doist/mcp-core
npm install @todoist/mcp-core
```

Previously published as `@doist/mcp-core`.

The MCP SDK and Zod are peer dependencies, so the server and the core share one copy of each. That matters: a host that serves several MCP servers unwraps them with `instanceof McpServer`, which fails against a second copy of the SDK.

| Peer | Range |
Expand Down Expand Up @@ -40,7 +42,7 @@ The MCP SDK and Zod are peer dependencies, so the server and the core share one
`McpTool<Params, Output, Context>` is generic over what each call receives, so each server picks its own context: an API client, or an object carrying one with an abort signal and a progress reporter. A server usually aliases it with its context filled in.

```ts
import type { McpTool } from '@doist/mcp-core'
import type { McpTool } from '@todoist/mcp-core'
import { z } from 'zod'
import type { NotesApi } from './notes-api.js'

Expand Down Expand Up @@ -71,8 +73,8 @@ export const findNotes = {
`createToolRegistrar` returns a function that registers tools on a server. Everything that differs between products comes in through its options:

```ts
import { createToolRegistrar } from '@doist/mcp-core'
import { McpServer } from '@modelcontextprotocol/server'
import { createToolRegistrar } from '@todoist/mcp-core'

export function getMcpServer({ token }: { token: string }): McpServer {
const server = new McpServer({ name: 'notes-mcp-server', version: '1.0.0' })
Expand Down Expand Up @@ -113,15 +115,15 @@ For each tool this:

### Serving a server from a host

`@doist/mcp-core/host` is the contract between a server package and a host that serves several of them, such as todoist-ai-integrations. Every server exports the same two shapes:
`@todoist/mcp-core/host` is the contract between a server package and a host that serves several of them, such as todoist-ai-integrations. Every server exports the same two shapes:

- `getMcpServer(options)`, taking `McpServerOptions` (`{ token, baseUrl? }`), or `McpServerOptions & { ... }` when it needs more;
- a `ValidateToken`: `(token, baseUrl?) => Promise<'valid' | 'invalid' | 'forbidden'>`.

A validator resolves only with a verdict on the token and rejects for anything else, so the host can retry a failure without caching it as a verdict. `validateBearerToken` builds one from a status-only `GET`:

```ts
import { validateBearerToken, type ValidateToken } from '@doist/mcp-core/host'
import { validateBearerToken, type ValidateToken } from '@todoist/mcp-core/host'

export const validateNotesToken: ValidateToken = (token, baseUrl = 'https://notes.example.com') =>
validateBearerToken({ url: `${baseUrl}/api/v1/me`, token })
Expand All @@ -145,7 +147,7 @@ import {
buildBearerChallenge,
createTokenVerdictCache,
isTransientValidationError,
} from '@doist/mcp-core/host'
} from '@todoist/mcp-core/host'

const verdicts = createTokenVerdictCache({ ttlMs: 120_000, maxEntries: 10_000 })

Expand Down Expand Up @@ -181,13 +183,13 @@ async function checkToken(token: string, baseUrl: string): Promise<Response | 'p

### Contract tests

`@doist/mcp-core/testing` holds suites a server runs over its own tool registry:
`@todoist/mcp-core/testing` holds suites a server runs over its own tool registry:

```ts
import {
describeAdvertisedToolSchemas,
describeOutputSchemaNullability,
} from '@doist/mcp-core/testing'
} from '@todoist/mcp-core/testing'
import { getMcpServer } from './mcp-server.js'
import { registeredTools } from './tool-registry.js'

Expand All @@ -206,7 +208,7 @@ Both take any `{ name, parameters, outputSchema? }`, so a server can run them be
Two more read only what a client receives, so they restate nothing about registration:

```ts
import { describeTokenFootprint, describeToolAnnotations } from '@doist/mcp-core/testing'
import { describeTokenFootprint, describeToolAnnotations } from '@todoist/mcp-core/testing'
import { encode } from 'gpt-tokenizer'

const createServer = () => getMcpServer({ token: 'test-token' })
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@doist/mcp-core",
"name": "@todoist/mcp-core",
"version": "0.0.0-development",
"description": "Shared core for the Doist MCP servers",
"type": "module",
Expand Down
Loading