8000 Make `schema.ts` the source of truth for error codes by jonathanhefner · Pull Request #1549 · modelcontextprotocol/modelcontextprotocol · GitHub
[go: up one dir, main page]

Skip to content

Conversation

jonathanhefner
Copy link
Member
@jonathanhefner jonathanhefner commented Sep 26, 2025

The goal of this PR is to make schema.ts the source of truth for which error codes to use in various scenarios. This was inspired by #509 and #1545.

I have added some comments for further discussion.

Comment on lines +678 to +680
export interface InvalidResourceError extends Error {
code: -32002;
}
Copy link
Member Author
@jonathanhefner jonathanhefner Sep 26, 2025

Choose a reason for hiding this comment

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

We could also explicitly define the message and data properties here, e.g.:

Suggested change
export interface InvalidResourceError extends Error {
code: -32002;
}
export interface InvalidResourceError extends Error {
code: -32002;
message: "Resource not found";
data: {
uri: string;
};
}

(Per this example.)

Comment on lines +783 to +789
export interface InvalidPromptError {
code: -32602;
}

export interface InvalidPromptArgumentsError {
code: -32602;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Another way to do this is to define a union type for the error message, e.g.:

Suggested change
export interface InvalidPromptError {
code: -32602;
}
export interface InvalidPromptArgumentsError {
code: -32602;
}
export interface PromptError {
code: -32602;
message:
| "Invalid prompt name"
| "Missing required arguments";
}

Though it may better to keep them separate if we want to define the data property as well.

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.

1 participant

0