-
Notifications
You must be signed in to change notification settings - Fork 969
Add plugin-defined MCP tools #988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
masonjames
wants to merge
9
commits into
emdash-cms:main
Choose a base branch
from
masonjames:codex/plugin-mcp-tools
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c61e4e3
Add plugin-defined MCP tools
masonjames 29aa5ba
Address plugin MCP tool review feedback
masonjames 557aa1e
Fix manifest schema projection validation
masonjames a78ec24
Merge branch 'main' into codex/plugin-mcp-tools
ascorbic ad3bce2
Address MCP JSON schema review follow-up
masonjames c66be2d
Merge branch 'main' into codex/plugin-mcp-tools
masonjames b0200a4
Merge branch 'main' into codex/plugin-mcp-tools
ascorbic 84dbc42
Merge upstream main into plugin MCP tools
masonjames 6055f5e
Merge branch 'main' into codex/plugin-mcp-tools
masonjames File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "emdash": patch | ||
| "@emdash-cms/plugin-types": patch | ||
| "@emdash-cms/registry-cli": patch | ||
| --- | ||
|
|
||
| Adds plugin-defined MCP tool metadata to plugin manifests and exposes enabled plugin tools through the EmDash MCP endpoint. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
docs/src/content/docs/plugins/creating-plugins/mcp-tools.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| --- | ||
| title: MCP Tools | ||
| description: Expose sandboxed plugin routes as tools on the site's MCP server. | ||
| --- | ||
|
|
||
| import { Aside } from "@astrojs/starlight/components"; | ||
|
|
||
| Plugin MCP tools let an AI assistant call one of your plugin routes through the site's built-in MCP server. Use them for admin-only actions that are useful from an assistant, such as summarizing plugin data, running an import preview, or querying plugin-owned storage. | ||
|
|
||
| ## Requirements | ||
|
|
||
| Plugin MCP tools are opt-in: | ||
|
|
||
| - Add the `mcp:tools` capability. | ||
| - Declare the route in `routes`. | ||
| - Add an `mcpTools` entry that points at that route. | ||
| - Use a lowercase snake_case tool name without double underscores. | ||
|
|
||
| MCP tool calls always require the `admin` token scope and an Admin user role. This is true even if the underlying plugin route is public. | ||
|
|
||
| ## Define a Tool | ||
|
|
||
| ```ts | ||
| import { definePlugin } from "emdash"; | ||
|
|
||
| export default definePlugin({ | ||
| routes: { | ||
| summarize: { | ||
| handler: async ({ input }) => { | ||
| const { text } = input as { text: string }; | ||
| return { summary: text.slice(0, 120) }; | ||
| }, | ||
| }, | ||
| }, | ||
| mcpTools: { | ||
| summarize: { | ||
| title: "Summarize Text", | ||
| description: "Summarize text using this plugin.", | ||
| route: "summarize", | ||
| inputSchema: { | ||
| type: "object", | ||
| properties: { | ||
| text: { | ||
| type: "string", | ||
| description: "Text to summarize.", | ||
| minLength: 1, | ||
| }, | ||
| }, | ||
| required: ["text"], | ||
| additionalProperties: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| Add the capability in the plugin descriptor or manifest: | ||
|
|
||
| ```ts | ||
| export default { | ||
| id: "my-plugin", | ||
| version: "1.0.0", | ||
| capabilities: ["mcp:tools"], | ||
| mcpTools: [ | ||
| { | ||
| name: "summarize", | ||
| title: "Summarize Text", | ||
| description: "Summarize text using this plugin.", | ||
| route: "summarize", | ||
| inputSchema: { | ||
| type: "object", | ||
| properties: { | ||
| text: { type: "string", description: "Text to summarize." }, | ||
| }, | ||
| required: ["text"], | ||
| additionalProperties: false, | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
| ``` | ||
|
|
||
| ## Input Schemas | ||
|
|
||
| Sandboxed plugin manifests cannot serialize Zod schemas, so MCP tools use a constrained JSON Schema object for input validation and client-facing descriptions. | ||
|
|
||
| Supported fields: | ||
|
|
||
| | Field | Applies to | | ||
| | --- | --- | | ||
| | `type` | `object`, `string`, `number`, `integer`, `boolean`, `array` | | ||
| | `description`, `default` | all schemas | | ||
| | `properties`, `required`, `additionalProperties` | object | | ||
| | `items`, `minItems`, `maxItems` | array | | ||
| | `enum` | string, number, integer, boolean | | ||
| | `format` | string: `date-time`, `email`, `uri`, `uuid` | | ||
| | `minLength`, `maxLength`, `pattern` | string | | ||
| | `minimum`, `maximum` | number, integer | | ||
|
|
||
| The root `inputSchema` must be an object. `$ref`, `$defs`, recursive schemas, `oneOf`, `anyOf`, and `allOf` are not supported. | ||
|
|
||
| <Aside> | ||
| Your route handler should still validate or narrow `input` before using it. The MCP input schema gives clients useful parameter information and rejects malformed MCP calls before dispatch. | ||
| </Aside> | ||
|
|
||
| ## Tool Names | ||
|
|
||
| The host generates the MCP tool name from the plugin id and the local tool name: | ||
|
|
||
| ```txt | ||
| @emdash-cms/plugin-forms + submit_form -> emdash_cms__plugin_forms__submit_form | ||
| ``` | ||
|
|
||
| Plugin id segments are joined with double underscores. Local tool names cannot contain double underscores so generated names stay unambiguous. | ||
|
|
||
| If a plugin id contains consecutive dashes, the host appends a short stable hash to keep the generated name collision-free. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.