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
30 changes: 30 additions & 0 deletions .github/workflows/publish-mcp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish MCP to npm

on:
push:
tags:
- "mcp-v*"

permissions:
contents: read
id-token: write

jobs:
publish:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/choosekit-mcp
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://registry.npmjs.org
package-manager-cache: false
- run: npm ci
- run: npm run check
- name: Verify release tag
run: |
node --input-type=module -e "import p from './package.json' with { type: 'json' }; if (process.env.GITHUB_REF_NAME !== 'mcp-v' + p.version) { throw new Error('Tag must match package version'); }"
- run: npm publish --access public
2 changes: 2 additions & 0 deletions packages/choosekit-mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ Ask independent named questions about the same context:

The result maps each question name to its decision, including separate token counts when available. Choice limits apply to each question.

Optional `concurrency` limits simultaneous questions. Omit it to run all questions concurrently.

### Images

To score images, add `imagePaths` in `labels` mode. Both tools accept this field alongside `context`; `chooseMany` shares the images across all questions.
Expand Down
12 changes: 6 additions & 6 deletions packages/choosekit-mcp/package-lock.json

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

4 changes: 2 additions & 2 deletions packages/choosekit-mcp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "choosekit-mcp",
"version": "0.5.0",
"version": "0.6.0",
"description": "Use choosekit as an MCP server.",
"license": "Apache-2.0",
"author": {
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@modelcontextprotocol/server": "2.0.0",
"choosekit": "^0.8.0",
"choosekit": "^0.9.0",
"zod": "^4.6.4"
},
"devDependencies": {
Expand Down
11 changes: 9 additions & 2 deletions packages/choosekit-mcp/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ function inputSchemas(backend: "llama-cpp" | "ollama" | "openrouter", mode: Choi
}) as z.ZodType<Record<string, z.infer<typeof questionSchema>>>;
return {
choose: z.object({ ...sharedFields, ...questionSchema.shape }).strict(),
chooseMany: z.object({ ...sharedFields, questions: questionsSchema }).strict(),
chooseMany: z.object({
...sharedFields,
questions: questionsSchema,
concurrency: z.number().int().positive()
.describe("Maximum simultaneous questions. Omit to run all questions concurrently.")
.optional(),
}).strict(),
};
}

Expand Down Expand Up @@ -180,14 +186,15 @@ export function buildServer(chooser: Chooser, options: ServerOptions = {}): McpS
openWorldHint: backend === "openrouter",
},
},
async ({ context, questions, imagePaths }, ctx) => {
async ({ context, questions, imagePaths, concurrency }, ctx) => {
try {
const images = imagePaths === undefined
? undefined
: await options.imageLoader!(imagePaths as readonly string[], ctx.mcpReq.signal);
const decisions = await chooseMany(chooser, {
context,
questions,
...(concurrency === undefined ? {} : { concurrency }),
...(images === undefined ? {} : { images }),
signal: ctx.mcpReq.signal,
});
Expand Down
31 changes: 30 additions & 1 deletion packages/choosekit-mcp/tests/server.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,38 @@ test("chooseMany starts independent questions together and loads shared images o
assert.equal(loads, 1);
for (const call of calls) {
assert.equal(call.context, manyRequest.context);
assert.equal(call.images, images);
assert.deepEqual(call.images, images);
assert.equal(call.signal, calls[0].signal);
}
});

test("chooseMany respects the requested concurrency", async (t) => {
for (const concurrency of [1, 2]) {
await t.test(`concurrency ${concurrency}`, async (t) => {
let active = 0;
let peak = 0;
let calls = 0;
const chooser = createChooser(async () => {
calls++;
peak = Math.max(peak, ++active);
await new Promise(setImmediate);
active--;
return { logprobs: [-0.1, -2], boundaryTokens: 0 };
});
const connection = await connect(chooser);
t.after(() => connection.close());
const questions = { ...manyRequest.questions, extra: manyRequest.questions.route };
const response = await connection.rpc("tools/call", {
name: "chooseMany", arguments: { ...manyRequest, questions, concurrency },
});
assert.notEqual(response.result.isError, true);
assert.deepEqual(Object.keys(response.result.structuredContent), Object.keys(questions));
assert.equal(calls, 3);
assert.equal(peak, concurrency);
});
}
});

test("chooseMany rejects invalid groups before calling the chooser", async (t) => {
let calls = 0;
const connection = await connect(async () => { calls++; }, { backend: "openrouter" });
Expand All @@ -152,6 +179,8 @@ test("chooseMany rejects invalid groups before calling the chooser", async (t) =
for (const arguments_ of [
{ ...manyRequest, questions: {} },
{ ...manyRequest, model: "test-model" },
...[0, -1, 1.5, "2", null, Number.MAX_SAFE_INTEGER + 1]
.map((concurrency) => ({ ...manyRequest, concurrency })),
{ ...manyRequest, questions: { route: { ...manyRequest.questions.route, question: " " } } },
{ ...manyRequest, questions: { route: { ...manyRequest.questions.route, model: "test-model" } } },
{ ...manyRequest, questions: { route: { question: request.question, choices: tooMany } } },
Expand Down
Loading