Skip to content

feat(server): accept Standard Schemas for elicitation#2369

Open
mattzcarey wants to merge 12 commits into
mainfrom
feat/elicitation-standard-schema
Open

feat(server): accept Standard Schemas for elicitation#2369
mattzcarey wants to merge 12 commits into
mainfrom
feat/elicitation-standard-schema

Conversation

@mattzcarey

Copy link
Copy Markdown
Contributor

Fixes #662.

Allows Server.elicitInput() and ctx.mcpReq.elicitInput() to accept a Standard Schema/Zod object as requestedSchema, converts it to the existing JSON Schema wire shape, and keeps JSON Schema input working unchanged.

Verification:

  • pnpm --filter @modelcontextprotocol/server test -- jsonSchemaValidatorOverride.test.ts
  • pnpm --filter @modelcontextprotocol/core typecheck
  • pnpm --filter @modelcontextprotocol/server typecheck
  • pnpm --filter @modelcontextprotocol/core lint
  • pnpm --filter @modelcontextprotocol/server lint
  • pnpm --filter @modelcontextprotocol/server build
  • pre-push hook: pnpm run typecheck:all, pnpm run build:all, pnpm run lint:all
  • git diff --check

@mattzcarey mattzcarey requested a review from a team as a code owner June 25, 2026 12:46
@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 12eb9e5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@modelcontextprotocol/core-internal Minor
@modelcontextprotocol/server Minor
@modelcontextprotocol/client Minor
@modelcontextprotocol/express Major
@modelcontextprotocol/fastify Major
@modelcontextprotocol/hono Major
@modelcontextprotocol/node Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2369

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2369

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2369

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2369

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2369

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2369

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2369

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2369

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2369

commit: 12eb9e5

Comment thread packages/server/src/server/server.ts Outdated
Comment thread packages/core-internal/src/shared/protocol.ts
Comment thread packages/core-internal/src/shared/protocol.ts
Comment thread packages/server/src/server/server.ts Outdated
Comment thread examples/server/src/serverGuide.examples.ts Outdated
@mattzcarey mattzcarey force-pushed the feat/elicitation-standard-schema branch from 01f43f4 to f732d6f Compare June 25, 2026 13:51
Comment thread packages/server/src/server/server.ts Outdated
Comment thread packages/server/src/server/server.ts Outdated
Comment thread examples/server/src/elicitationFormExample.ts Outdated

@felixweinberger felixweinberger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

Comment thread packages/server/src/server/server.ts Outdated
Comment thread packages/server/src/server/server.ts Outdated
Comment thread packages/core-internal/src/shared/elicitation.ts
Comment thread .changeset/standard-schema-elicitation.md
Comment thread examples/server/src/elicitationFormExample.ts Outdated
@mattzcarey mattzcarey force-pushed the feat/elicitation-standard-schema branch from 918c601 to a300f51 Compare July 1, 2026 09:18
Comment thread packages/server/src/server/server.ts
Comment thread packages/core-internal/src/shared/elicitation.ts
Comment thread packages/core-internal/src/shared/elicitation.ts
Comment thread packages/server/src/server/server.ts
@mattzcarey mattzcarey force-pushed the feat/elicitation-standard-schema branch from 15e6243 to 12eb9e5 Compare July 6, 2026 19:01
@mattzcarey mattzcarey enabled auto-merge (squash) July 6, 2026 19:02

@felixweinberger felixweinberger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly wondering if we should be updating the elicitInput API given we want people to use inputRequired for MRTR going forward.

* both eras, this only works on the legacy path.
*/
elicitInput: (params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions) => Promise<ElicitResult>;
elicitInput: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deprecated API, we don't really want people to continue you building on this, but consolidate on the inputRequired form - there's a backwards compatibility shim that allows people to write the MRTR based elicitation but still serve 2025-11-25 based servers with it.

Given that, I feel like we should instead mark this API @deprecated and not take on the effort of making it StandardSchema compatible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would also remove the need for the overload introduced further down.

* @param options Optional request options.
* @returns The result of the elicitation request.
*
* @deprecated Throws on a 2026-07-28-era request — use {@link index.inputRequired | inputRequired} (multi-round-trip)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see it's already marked deprecated here - rather than make it compatible with standard schema should we keep it simple and leave this out and push people to use inputRequired if they want to use standardSchema?

Comment on lines 125 to +134
export const inputRequired: InputRequiredBuilder = Object.assign(buildInputRequired, {
elicit(params: Omit<ElicitRequestFormParams, 'mode'> & { mode?: 'form' }): InputRequest {
return { method: 'elicitation/create', params: { ...params, mode: 'form' } };
elicit(
params:
| (Omit<ElicitRequestFormParams, 'mode'> & { mode?: 'form' })
| (Omit<ElicitInputFormParams<StandardSchemaWithJSON>, 'mode'> & { mode?: 'form' })
): InputRequest {
const { params: normalizedParams } = normalizeElicitInputFormParams(
params as ElicitRequestFormParams | ElicitInputFormParams<StandardSchemaWithJSON>
);
return { method: 'elicitation/create', params: normalizedParams };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this could be cleaned up with something like this?

elicit(params: ElicitInputParams): InputRequest {
    try {
        const { params: normalizedParams } = normalizeElicitInputFormParams(params);
        return { method: 'elicitation/create', params: normalizedParams };
    } catch (error) {
        throw error instanceof ProtocolError ? new TypeError(error.message, { cause: error }) : error;
    }
},

Instead of the type assertions & Omit<...>s?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Zod schema with Elicitation?

2 participants