Repository navigation
feat(coding-agent): support ACP MCP programs #1378
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
30b44fa
feat(coding-agent): support ACP MCP programs
hallerite e2be977
Merge main into ACP MCP programs branch
sethkarten cde5c8c
feat(coding-agent): port ACP MCP servers to kernel runtime
sethkarten a5c4d7c
fix(coding-agent): fence ACP MCP daemon ownership
sethkarten 5a73b61
fix(coding-agent): release ACP MCP leases on detach
sethkarten fb73d3a
test(coding-agent): preserve daemon prototype fixtures
sethkarten 8e13c95
fix(coding-agent): roll back failed ACP MCP claims
sethkarten b2a213a
fix(coding-agent): reap ACP MCP transports on release
sethkarten 8e525ed
fix(coding-agent): isolate ACP MCP release failures
sethkarten 80136a7
fix(coding-agent): retry empty-session MCP cleanup
sethkarten 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
Some comments aren't visible on the classic Files Changed page.
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 @@ | ||
| - Added session-scoped ACP MCP servers through the kernel MCP program API ([#1378](https://github.com/PrimeIntellect-ai/prime-agent/pull/1378) by [@hallerite](https://github.com/hallerite)). |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export type AcpMcpServerConfig = | ||
| | { | ||
| name: string; | ||
| type: "http"; | ||
| url: string; | ||
| headers: Record<string, string>; | ||
| } | ||
| | { | ||
| name: string; | ||
| type: "stdio"; | ||
| command: string; | ||
| args: string[]; | ||
| cwd: string; | ||
| env: Record<string, string>; | ||
| }; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { validateHeaderName, validateHeaderValue } from "node:http"; | ||
| import type { McpServer } from "@agentclientprotocol/sdk"; | ||
| import { RequestError } from "@agentclientprotocol/sdk"; | ||
| import type { AcpMcpServerConfig } from "../../core/mcp/acp-mcp-types.js"; | ||
|
|
||
| const SERVER_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/; | ||
|
|
||
| function entries( | ||
| server: string, | ||
| label: "header" | "environment", | ||
| values: readonly { name: string; value: string }[], | ||
| ): Record<string, string> { | ||
| const result = Object.create(null) as Record<string, string>; | ||
| const seen = new Set<string>(); | ||
| for (const entry of values) { | ||
| if (!entry.name) { | ||
| throw RequestError.invalidParams({ reason: `MCP server ${server} has an empty ${label} name` }); | ||
| } | ||
| const identity = label === "header" ? entry.name.toLowerCase() : entry.name; | ||
| if (seen.has(identity)) { | ||
| throw RequestError.invalidParams({ | ||
| reason: `MCP server ${server} has duplicate ${label} ${entry.name}`, | ||
| }); | ||
| } | ||
| if (label === "header") { | ||
| try { | ||
| validateHeaderName(entry.name); | ||
| validateHeaderValue(entry.name, entry.value); | ||
| } catch { | ||
| throw RequestError.invalidParams({ reason: `MCP server ${server} has an invalid HTTP header` }); | ||
| } | ||
| } else if (entry.name.includes("=") || entry.name.includes("\0") || entry.value.includes("\0")) { | ||
| throw RequestError.invalidParams({ reason: `MCP server ${server} has an invalid environment entry` }); | ||
| } | ||
| seen.add(identity); | ||
| result[entry.name] = entry.value; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| export function resolveAcpMcpServers(servers: readonly McpServer[], cwd: string): AcpMcpServerConfig[] { | ||
| const names = new Set<string>(); | ||
| return servers.map((server) => { | ||
| if (!SERVER_NAME_PATTERN.test(server.name)) { | ||
| throw RequestError.invalidParams({ | ||
| reason: | ||
| "MCP server names must start with an alphanumeric character and contain at most 64 alphanumeric, underscore, or hyphen characters", | ||
| }); | ||
| } | ||
| if (names.has(server.name)) { | ||
| throw RequestError.invalidParams({ reason: `duplicate MCP server name: ${server.name}` }); | ||
| } | ||
| names.add(server.name); | ||
|
|
||
| if ("command" in server) { | ||
| if (!server.command) { | ||
| throw RequestError.invalidParams({ reason: `MCP server ${server.name} has no stdio command` }); | ||
| } | ||
| if (server.command.includes("\0") || server.args.some((argument) => argument.includes("\0"))) { | ||
| throw RequestError.invalidParams({ reason: `MCP server ${server.name} has an invalid stdio command` }); | ||
| } | ||
| return { | ||
| name: server.name, | ||
| type: "stdio", | ||
| command: server.command, | ||
| args: [...server.args], | ||
| cwd, | ||
| env: entries(server.name, "environment", server.env), | ||
| }; | ||
| } | ||
|
|
||
| if (server.type !== "http") { | ||
| throw RequestError.invalidParams({ | ||
| reason: `MCP server ${server.name} uses unsupported ${server.type} transport`, | ||
| }); | ||
| } | ||
| let url: URL; | ||
| try { | ||
| url = new URL(server.url); | ||
| } catch { | ||
| throw RequestError.invalidParams({ reason: `MCP server ${server.name} has an invalid HTTP URL` }); | ||
| } | ||
| if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password) { | ||
| throw RequestError.invalidParams({ | ||
| reason: `MCP server ${server.name} must use an HTTP(S) URL without embedded credentials`, | ||
| }); | ||
| } | ||
| return { | ||
| name: server.name, | ||
| type: "http", | ||
| url: url.toString(), | ||
| headers: entries(server.name, "header", server.headers), | ||
| }; | ||
| }); | ||
| } |
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.