@unbrained/pm-cli 2026.8.25 → 2026.8.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/HARNESS_COMPATIBILITY.md +32 -0
- package/.agents/skills/README.md +47 -0
- package/.agents/skills/pm-developer/SKILL.md +117 -0
- package/.agents/skills/pm-developer/references/COMMAND_PLAYBOOK.md +49 -0
- package/.agents/skills/pm-developer/references/GRAPH_AND_RELATIONSHIPS.md +91 -0
- package/.agents/skills/pm-developer/references/MULTI_AGENT_MERGE.md +72 -0
- package/.agents/skills/pm-developer/references/PROMPTS.md +17 -0
- package/.agents/skills/pm-developer/references/SCRIPTING_COMPOSITION.md +82 -0
- package/.agents/skills/pm-developer/references/TOKEN_BUDGETS.md +85 -0
- package/.agents/skills/pm-extensions/SKILL.md +106 -0
- package/.agents/skills/pm-extensions/references/AUTHORING.md +95 -0
- package/.agents/skills/pm-extensions/references/LIFECYCLE.md +40 -0
- package/.agents/skills/pm-extensions/references/TROUBLESHOOTING.md +25 -0
- package/.agents/skills/pm-sdk/SKILL.md +107 -0
- package/.agents/skills/pm-sdk/references/DOMAIN_MODELING.md +78 -0
- package/.agents/skills/pm-sdk/references/INTEGRATION_CHECKLIST.md +31 -0
- package/.agents/skills/pm-sdk/references/PROMPTS.md +13 -0
- package/.agents/skills/pm-sdk/references/SURFACE_MAP.md +82 -0
- package/.agents/skills/pm-user/SKILL.md +111 -0
- package/.agents/skills/pm-user/references/BACKLOG_SHAPING.md +105 -0
- package/.agents/skills/pm-user/references/PROMPTS.md +17 -0
- package/.agents/skills/pm-user/references/WORKFLOWS.md +35 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +58 -3
- package/README.md +8 -5
- package/dist/cli/commander-usage.js +11 -7
- package/dist/cli/error-guidance.js +3 -3
- package/dist/cli/help-content.d.ts +2 -0
- package/dist/cli/help-content.js +53 -17
- package/dist/cli/help-json-payload.d.ts +8 -2
- package/dist/cli/help-json-payload.js +46 -12
- package/dist/cli/main.js +52 -74
- package/dist/cli/register-annotations.js +27 -21
- package/dist/cli/register-setup.js +98 -57
- package/dist/cli-bundle/bundle-manifest.json +156 -156
- package/dist/cli-bundle/chunks/chunk-3OO3W6FW.js +202 -0
- package/dist/cli-bundle/chunks/chunk-52EKTW6V.js +3 -0
- package/dist/cli-bundle/chunks/{chunk-QLUORNIB.js → chunk-CVBBGWW5.js} +62 -44
- package/dist/cli-bundle/chunks/chunk-MFNTKMTI.js +13 -0
- package/dist/cli-bundle/chunks/chunk-OS27HHBN.js +35 -0
- package/dist/cli-bundle/chunks/chunk-QTO7USTH.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-5I5RWIJC.js → chunk-R4ETAOJC.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-OWHNAR2B.js → chunk-SH6P7FXI.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-SHMDY36D.js +8 -0
- package/dist/cli-bundle/chunks/{chunk-244MI4GS.js → chunk-SKXLJIEK.js} +60 -60
- package/dist/cli-bundle/chunks/chunk-TNX6HC54.js +3 -0
- package/dist/cli-bundle/chunks/{register-list-query-XVN2ZLI7.js → register-list-query-EUWM6VII.js} +2 -2
- package/dist/cli-bundle/chunks/{register-mutation-QCKAEGIJ.js → register-mutation-FD4HSAVU.js} +4 -4
- package/dist/cli-bundle/chunks/{register-operations-SDEAXE7E.js → register-operations-HRMNFEC3.js} +2 -2
- package/dist/cli-bundle/chunks/register-setup-33GNICLX.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-IBZZZGK3.js → chunk-2AGZ5BRT.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-4BR5UU52.js +50 -0
- package/dist/cli-bundle/focused-chunks/{chunk-OHIHZ7HS.js → chunk-6GCRSLPG.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-OVJL6NZE.js → chunk-AD6ULRAF.js} +4 -4
- package/dist/cli-bundle/focused-chunks/{chunk-7YCDTCBC.js → chunk-AQ5IYEZZ.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-YO3ZF3FI.js → chunk-EKX37ZHA.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-N7W67YIG.js → chunk-FC2AXLB5.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-H5JZEIQV.js → chunk-HC7ODMH3.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-NOOZGIXP.js → chunk-HVQ22RC4.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-A644DUFQ.js → chunk-MEASX544.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-RAFKLNZX.js → chunk-MXTYGECH.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-2UIWOP3O.js → chunk-SUBSWYW3.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-VXWATRFL.js → chunk-XDPYBQCF.js} +9 -9
- package/dist/cli-bundle/focused-chunks/{chunk-XUQPEKRN.js → chunk-Y3JJXRVK.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-GQR3WH3F.js → chunk-Y5A7SJJ7.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-YHWHX6YY.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-ONYQCALA.js → chunk-YVVZ3LQ6.js} +6 -6
- package/dist/cli-bundle/focused-chunks/chunk-Z2USIBR2.js +5 -0
- package/dist/cli-bundle/main.js +15 -14
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +2 -2
- package/dist/cli-bundle/sdk-core.js +31 -31
- package/dist/cli-bundle/sdk-governance.js +1 -1
- package/dist/cli-bundle/sdk-graph.js +1 -1
- package/dist/cli-bundle/sdk-merge.js +31 -31
- package/dist/cli-bundle/sdk-query.js +1 -1
- package/dist/cli-bundle/sdk-runtime.js +1 -1
- package/dist/cli-bundle/sdk-testing.js +1 -1
- package/dist/cli-bundle/sdk.js +32 -6
- package/dist/core/extensions/manifest-schema.d.ts +20 -0
- package/dist/core/extensions/manifest-schema.js +28 -10
- package/dist/core/governance/issue-codes.d.ts +11 -2
- package/dist/core/governance/issue-codes.js +29 -10
- package/dist/core/item/item-format.js +3 -3
- package/dist/core/store/item-store.js +12 -5
- package/dist/mcp/http-server.d.ts +60 -0
- package/dist/mcp/http-server.js +451 -0
- package/dist/mcp/legacy-adapter.d.ts +50 -0
- package/dist/mcp/legacy-adapter.js +64 -0
- package/dist/mcp/server.d.ts +42 -9
- package/dist/mcp/server.js +572 -59
- package/dist/mcp/tool-definitions.d.ts +2 -0
- package/dist/mcp/tool-definitions.js +2 -2
- package/dist/sdk/agent/closed-domain-contracts.d.ts +1 -1
- package/dist/sdk/agent/closed-domain-contracts.js +24 -2
- package/dist/sdk/agent/refusal-closure-census.d.ts +6 -2
- package/dist/sdk/agent/refusal-closure-census.js +16 -8
- package/dist/sdk/agent-capability-contracts.js +6 -2
- package/dist/sdk/cli-bootstrap.js +3 -2
- package/dist/sdk/cli-contracts/command-aliases.js +15 -2
- package/dist/sdk/cli-contracts/enum-contracts.d.ts +4 -1
- package/dist/sdk/cli-contracts/enum-contracts.js +7 -2
- package/dist/sdk/cli-contracts/flag-contracts.js +9 -5
- package/dist/sdk/cli-contracts/grammar-contracts.d.ts +3 -3
- package/dist/sdk/cli-contracts/grammar-contracts.js +24 -17
- package/dist/sdk/cli-contracts/runtime-contracts.js +13 -11
- package/dist/sdk/cli-contracts/tool-schema.js +18 -15
- package/dist/sdk/cli-contracts.d.ts +1 -1
- package/dist/sdk/cli-contracts.js +3 -3
- package/dist/sdk/cli-program.js +3 -2
- package/dist/sdk/completion.js +40 -13
- package/dist/sdk/compose.d.ts +4 -1
- package/dist/sdk/compose.js +23 -36
- package/dist/sdk/extension/author-manifest.d.ts +22 -0
- package/dist/sdk/extension/author-manifest.js +93 -0
- package/dist/sdk/extension.js +6 -3
- package/dist/sdk/generated/generated-error-code-catalog-part-1.js +20 -5
- package/dist/sdk/generated/generated-error-code-catalog-part-2.js +18 -3
- package/dist/sdk/governance/health.js +7 -2
- package/dist/sdk/governance/upgrade.d.ts +2 -0
- package/dist/sdk/governance/upgrade.js +30 -8
- package/dist/sdk/governance/validate.js +8 -6
- package/dist/sdk/guide-topics.js +6 -6
- package/dist/sdk/index.d.ts +10 -2
- package/dist/sdk/index.js +11 -3
- package/dist/sdk/mcp/apps.d.ts +70 -0
- package/dist/sdk/mcp/apps.js +154 -0
- package/dist/sdk/mcp/authorization.d.ts +134 -0
- package/dist/sdk/mcp/authorization.js +405 -0
- package/dist/sdk/mcp/interactions.d.ts +118 -0
- package/dist/sdk/mcp/interactions.js +337 -0
- package/dist/sdk/mcp/protocol.d.ts +142 -0
- package/dist/sdk/mcp/protocol.js +174 -0
- package/dist/sdk/mcp/skills.d.ts +127 -0
- package/dist/sdk/mcp/skills.js +390 -0
- package/dist/sdk/mcp/subscriptions.d.ts +65 -0
- package/dist/sdk/mcp/subscriptions.js +212 -0
- package/dist/sdk/mcp/tasks.d.ts +107 -0
- package/dist/sdk/mcp/tasks.js +431 -0
- package/dist/sdk/mcp/transport.d.ts +30 -0
- package/dist/sdk/mcp/transport.js +261 -0
- package/dist/sdk/merge/receipts.d.ts +16 -0
- package/dist/sdk/merge/receipts.js +9 -8
- package/dist/sdk/read-output-contracts.js +16 -3
- package/dist/sdk/runtime-action-aliases.js +7 -3
- package/dist/sdk/runtime-input.js +12 -4
- package/dist/sdk/runtime-primitives.d.ts +2 -2
- package/dist/sdk/runtime-primitives.js +4 -4
- package/dist/sdk/test/execution.d.ts +6 -0
- package/dist/sdk/test/execution.js +32 -3
- package/docs/AGENT_PROVENANCE_ADR.md +6 -4
- package/docs/AGENT_RUNTIME_PRIMITIVES.md +6 -5
- package/docs/CLAUDE_CODE_PLUGIN.md +12 -5
- package/docs/CLI_GRAMMAR.md +7 -1
- package/docs/COMMANDS.md +2 -2
- package/docs/DIAGNOSTIC_OUTPUT_CONTRACTS.md +8 -0
- package/docs/EXTENSIONS.md +36 -36
- package/docs/MCP_2026_07_28.md +160 -0
- package/docs/MCP_2026_07_28_CONFORMANCE.md +30 -0
- package/docs/MCP_REMOTE_TRANSPORT_SECURITY.md +180 -0
- package/docs/MCP_SKILLS_AND_APPS.md +107 -0
- package/docs/QUICKSTART.md +15 -15
- package/docs/README.md +5 -0
- package/docs/RELEASING.md +12 -3
- package/docs/SDK.md +22 -1
- package/docs/SDK_AGENT_SESSION_CONTEXT.md +18 -13
- package/docs/SDK_CONTEXT_INTEGRITY.md +6 -0
- package/docs/SDK_EVIDENCE_TRACEABILITY.md +9 -1
- package/docs/SDK_MCP_INTERACTIONS.md +227 -0
- package/docs/TESTING.md +4 -0
- package/docs/generated/AGENT_CAPABILITY_ROUTING.md +1 -1
- package/docs/generated/REFUSAL_CLOSURE_CENSUS.md +13 -11
- package/marketplace.json +2 -2
- package/package.json +15 -11
- package/packages/pm-beads/README.md +12 -6
- package/packages/pm-beads/docs/MIGRATION.md +53 -0
- package/packages/pm-beads/extensions/beads/index.ts +8 -0
- package/packages/pm-beads/extensions/beads/runtime.ts +671 -112
- package/packages/pm-beads/package.json +1 -1
- package/packages/pm-calendar/package.json +1 -1
- package/packages/pm-command-kit/package.json +1 -1
- package/packages/pm-digital-twin/package.json +1 -1
- package/packages/pm-governance-audit/package.json +1 -1
- package/packages/pm-guide-shell/package.json +1 -1
- package/packages/pm-kanban/package.json +1 -1
- package/packages/pm-lifecycle-hooks/package.json +1 -1
- package/packages/pm-linked-test-adapters/package.json +1 -1
- package/packages/pm-search-advanced/package.json +1 -1
- package/packages/pm-templates/package.json +1 -1
- package/packages/pm-todos/package.json +1 -1
- package/packages/pm-vcs/package.json +1 -1
- package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
- package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
- package/scripts/finalize-build.mjs +1 -0
- package/sdk/public-surface.json +902 -54
- package/dist/cli-bundle/chunks/chunk-2F3LUFMW.js +0 -8
- package/dist/cli-bundle/chunks/chunk-65MHLHAA.js +0 -2
- package/dist/cli-bundle/chunks/chunk-6C7GIMIL.js +0 -13
- package/dist/cli-bundle/chunks/chunk-QKGMHGEI.js +0 -202
- package/dist/cli-bundle/chunks/chunk-T2ENPRXF.js +0 -3
- package/dist/cli-bundle/chunks/chunk-TPQIBSL2.js +0 -3
- package/dist/cli-bundle/chunks/chunk-YQMYF3YD.js +0 -35
- package/dist/cli-bundle/chunks/register-setup-LXVBRCJ3.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-42S3GGZ7.js +0 -50
- package/dist/cli-bundle/focused-chunks/chunk-7I23XGWO.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-LMKG3DFE.js +0 -5
package/dist/mcp/server.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Runs the MCP server adapter that exposes pm actions and contracts to external agents.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
8
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="77067047-62fc-54e8-9047-ad30580d6125")}catch(e){}}();
|
|
9
9
|
import { realpathSync } from "node:fs";
|
|
10
10
|
import { readFile } from "node:fs/promises";
|
|
11
11
|
import path from "node:path";
|
|
@@ -22,7 +22,15 @@ import { isRuntimeRecord, markMcpMutationTransportInput, } from "../sdk/runtime-
|
|
|
22
22
|
import { attachOutputTokenAccounting } from "../sdk/output-token-accounting.js";
|
|
23
23
|
import { createReproducibleProcessRunner, runWithReproducibleProcessEnvironment, } from "../sdk/reproducibility/process.js";
|
|
24
24
|
import { parseAtomicMutationControls, resolveItemMutationDocument, } from "../sdk/structured-mutations.js";
|
|
25
|
-
import { resolveAuthor, resolvePmRoot } from "../sdk/runtime-primitives.js";
|
|
25
|
+
import { resolveAuthor, resolvePmRoot, resolveWorkspaceRoot, } from "../sdk/runtime-primitives.js";
|
|
26
|
+
import { PM_MCP_ERROR_CODES, PM_MCP_META_KEYS, PM_MCP_PROTOCOL_VERSION, PmMcpProtocolError, attachMcpServerInfo, buildMcpCompleteResult, buildMcpDiscoverResult, hasMcpClientExtension, isMcpRecord, resolveMcpRequestContext, } from "../sdk/mcp/protocol.js";
|
|
27
|
+
import { PmMcpInputRequiredError, buildMcpInputRequiredResult, parseMcpInputResponses, validateMcpJsonSchema, withMcpCachePolicy, } from "../sdk/mcp/interactions.js";
|
|
28
|
+
import { PM_MCP_TASKS_EXTENSION, createMcpTaskStore, } from "../sdk/mcp/tasks.js";
|
|
29
|
+
import { PmMcpSubscriptionRegistry, } from "../sdk/mcp/subscriptions.js";
|
|
30
|
+
import { extractMcpTraceContext, runWithMcpTraceContext, } from "../sdk/mcp/authorization.js";
|
|
31
|
+
import { LegacyMcpAdapter } from "./legacy-adapter.js";
|
|
32
|
+
import { PM_MCP_APP_CONTRACTS, PM_MCP_APP_MIME_TYPE, PM_MCP_APPS_EXTENSION, PM_MCP_APPS_SERVER_CAPABILITY, decoratePmMcpToolsWithApps, findPmMcpAppByUri, hasPmMcpAppsCapability, renderPmMcpAppHtml, } from "../sdk/mcp/apps.js";
|
|
33
|
+
import { PM_MCP_SKILLS_EXTENSION, PM_MCP_SKILLS_SERVER_CAPABILITY, PmMcpSkillRegistry, assertPmMcpSkillsCapability, } from "../sdk/mcp/skills.js";
|
|
26
34
|
function runMcpAction(args) {
|
|
27
35
|
return runAction(markMcpMutationTransportInput(args));
|
|
28
36
|
}
|
|
@@ -37,7 +45,68 @@ if (typeof process.env[PM_PACKAGE_ROOT_ENV] !== "string" ||
|
|
|
37
45
|
// Reflect the real package.json version so agents/telemetry can identify the
|
|
38
46
|
// build serving requests (was hard-coded "1.0.0"; see pm-2nvw).
|
|
39
47
|
const PM_MCP_SERVER_VERSION = resolvePmCliVersion(import.meta.url, ["../.."]) ?? "0.0.0";
|
|
40
|
-
|
|
48
|
+
const PM_MCP_SERVER_INFO = {
|
|
49
|
+
name: "pm-mcp",
|
|
50
|
+
version: PM_MCP_SERVER_VERSION,
|
|
51
|
+
description: "Stateless project-context management through pm SDK contracts.",
|
|
52
|
+
websiteUrl: "https://github.com/unbraind/pm-cli",
|
|
53
|
+
};
|
|
54
|
+
const PM_MCP_SERVER_CAPABILITIES = {
|
|
55
|
+
prompts: { listChanged: true },
|
|
56
|
+
resources: { listChanged: true, subscribe: true },
|
|
57
|
+
tools: { listChanged: true },
|
|
58
|
+
extensions: {
|
|
59
|
+
[PM_MCP_TASKS_EXTENSION]: {},
|
|
60
|
+
[PM_MCP_APPS_EXTENSION]: PM_MCP_APPS_SERVER_CAPABILITY,
|
|
61
|
+
[PM_MCP_SKILLS_EXTENSION]: PM_MCP_SKILLS_SERVER_CAPABILITY,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const PM_MCP_SUBSCRIPTIONS = new Map();
|
|
65
|
+
function createMcpSubscriptionRegistry() {
|
|
66
|
+
return new PmMcpSubscriptionRegistry({
|
|
67
|
+
capabilities: PM_MCP_SERVER_CAPABILITIES,
|
|
68
|
+
serverInfo: PM_MCP_SERVER_INFO,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function pruneClosedMcpSubscriptionRegistries() {
|
|
72
|
+
for (const [key, subscription] of PM_MCP_SUBSCRIPTIONS) {
|
|
73
|
+
if (subscription.registry.size === 0)
|
|
74
|
+
PM_MCP_SUBSCRIPTIONS.delete(key);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const PM_MCP_CACHE_POLICIES = {
|
|
78
|
+
prompts: { ttlMs: 60_000, cacheScope: "public" },
|
|
79
|
+
resource: { ttlMs: 0, cacheScope: "private" },
|
|
80
|
+
resources: { ttlMs: 60_000, cacheScope: "public" },
|
|
81
|
+
tools: { ttlMs: 30_000, cacheScope: "private" },
|
|
82
|
+
};
|
|
83
|
+
const PM_MCP_DIRECT_TASK_TOOLS = new Set([
|
|
84
|
+
"pm_graph",
|
|
85
|
+
"pm_health",
|
|
86
|
+
"pm_validate",
|
|
87
|
+
]);
|
|
88
|
+
const PM_MCP_RUN_TASK_ACTIONS = new Set([
|
|
89
|
+
"graph",
|
|
90
|
+
"health",
|
|
91
|
+
"import",
|
|
92
|
+
"reindex",
|
|
93
|
+
"test-all",
|
|
94
|
+
"validate",
|
|
95
|
+
]);
|
|
96
|
+
const PM_MCP_SKILL_METHODS = new Set([
|
|
97
|
+
"skills/list",
|
|
98
|
+
"skills/get",
|
|
99
|
+
"resources/directory/read",
|
|
100
|
+
]);
|
|
101
|
+
const PM_MCP_INSTRUCTIONS = "You have access to native pm CLI tools for git-based project management. " +
|
|
102
|
+
"Use pm_next to pick the next actionable item, or pm_context or pm_search before creating new work. " +
|
|
103
|
+
"Prefer narrow tools (pm_next, pm_context, pm_list, pm_get, pm_search, pm_events, pm_create, pm_mutate, pm_copy, pm_focus, pm_update, pm_append, pm_claim, pm_release, pm_close, pm_comments, pm_files, pm_docs, pm_notes, pm_learnings, pm_deps, pm_graph, pm_test, pm_validate, pm_health, pm_contracts, pm_schema, pm_profile, pm_config, pm_plan) over pm_run when they cover the operation. " +
|
|
104
|
+
"Use pm_plan for agent harness Plan workflows: it provides Codex/Claude/Cursor-style planning with durable steps, dependencies, decisions, discoveries, validation, and materialization. " +
|
|
105
|
+
"Use pm_schema and pm_config for workspace configuration: pm_schema manages custom item types/statuses and pm_config reads or writes settings keys. " +
|
|
106
|
+
"Use pm_run with an explicit action for active package-owned operations, plus activity, aggregate, history, stats, test-all, and gc. " +
|
|
107
|
+
"Use history-redact for audited history-stream redaction workflows, history-repair to re-anchor a drifted history chain, and history-compact to checkpoint/prune long history streams while preserving replay integrity. " +
|
|
108
|
+
"Agent harness and model provenance are detected automatically; pass author only for an intentional identity override. " +
|
|
109
|
+
"Do not pass path during real repository tracking — only pass path for sandbox or test runs.";
|
|
41
110
|
// Tool definitions (TOOLS) live in ./tool-definitions.ts so the `pm contracts`
|
|
42
111
|
// golden-file snapshot can import the surface without loading the server
|
|
43
112
|
// runtime (pm-4os2). This file owns dispatch, normalization, and transport.
|
|
@@ -75,6 +144,7 @@ function nearestDeclaredKey(unexpected, declared) {
|
|
|
75
144
|
// accept arbitrary top-level keys (see extensionOptionsFromArgs), so unexpected
|
|
76
145
|
// keys there are by-design rather than typos and must not be flagged.
|
|
77
146
|
const UNEXPECTED_KEY_WARNING_EXEMPT_TOOLS = new Set(["pm_run"]);
|
|
147
|
+
const MCP_RETRY_ARGUMENT_KEYS = new Set(["inputResponses", "requestState"]);
|
|
78
148
|
function detectUnexpectedTopLevelKeys(toolName, args, toolDeclaredKeys = declaredToolKeys()) {
|
|
79
149
|
if (typeof args !== "object" || args === null || Array.isArray(args)) {
|
|
80
150
|
return [];
|
|
@@ -86,7 +156,7 @@ function detectUnexpectedTopLevelKeys(toolName, args, toolDeclaredKeys = declare
|
|
|
86
156
|
if (declared === undefined) {
|
|
87
157
|
return [];
|
|
88
158
|
}
|
|
89
|
-
const declaredSet = new Set(declared);
|
|
159
|
+
const declaredSet = new Set([...declared, ...MCP_RETRY_ARGUMENT_KEYS]);
|
|
90
160
|
const warnings = [];
|
|
91
161
|
for (const key of Object.keys(args)) {
|
|
92
162
|
if (declaredSet.has(key)) {
|
|
@@ -265,10 +335,8 @@ function boundMcpClientProvenance(value) {
|
|
|
265
335
|
}
|
|
266
336
|
return bounded;
|
|
267
337
|
}
|
|
268
|
-
function readMcpClientInfo(
|
|
269
|
-
const clientInfo = isRuntimeRecord(
|
|
270
|
-
? params.clientInfo
|
|
271
|
-
: {};
|
|
338
|
+
function readMcpClientInfo(value) {
|
|
339
|
+
const clientInfo = isRuntimeRecord(value) ? value : {};
|
|
272
340
|
const clientName = typeof clientInfo.name === "string" ? clientInfo.name.trim() : "";
|
|
273
341
|
if (clientName.length === 0)
|
|
274
342
|
return undefined;
|
|
@@ -292,11 +360,20 @@ function readMcpClientInfo(params) {
|
|
|
292
360
|
result.episode = episode;
|
|
293
361
|
return result;
|
|
294
362
|
}
|
|
295
|
-
async function
|
|
363
|
+
async function emitMcpChangeNotifications(action) {
|
|
364
|
+
if (isMutationAction(action ?? "")) {
|
|
365
|
+
await Promise.all([...PM_MCP_SUBSCRIPTIONS.values()].flatMap(({ registry }) => PM_MCP_RESOURCE_CONTRACTS.map((resource) => registry.emitResourceUpdated(resource.uri))));
|
|
366
|
+
}
|
|
367
|
+
if (["extension", "install", "package", "uninstall"].includes(action ?? "")) {
|
|
368
|
+
await Promise.all([...PM_MCP_SUBSCRIPTIONS.values()].map(({ registry }) => registry.emitListChanged("tools")));
|
|
369
|
+
}
|
|
370
|
+
pruneClosedMcpSubscriptionRegistries();
|
|
371
|
+
}
|
|
372
|
+
async function handleToolCall(paramsInput, clientInfo) {
|
|
296
373
|
return runWithHarnessDetectionSignals({
|
|
297
374
|
env: process.env,
|
|
298
375
|
argv: process.argv,
|
|
299
|
-
...(
|
|
376
|
+
...(clientInfo ? { client_info: clientInfo } : {}),
|
|
300
377
|
}, async () => {
|
|
301
378
|
const params = asRecordClone(paramsInput);
|
|
302
379
|
const name = readRequiredString(params, "name");
|
|
@@ -306,7 +383,16 @@ async function handleToolCall(paramsInput) {
|
|
|
306
383
|
if (!handler) {
|
|
307
384
|
throw new PmCliError(`Unknown pm MCP tool: ${name}`, 64);
|
|
308
385
|
}
|
|
309
|
-
const
|
|
386
|
+
const inputResponses = params.inputResponses === undefined
|
|
387
|
+
? undefined
|
|
388
|
+
: parseMcpInputResponses(params.inputResponses);
|
|
389
|
+
const requestedArgs = {
|
|
390
|
+
...decodeHtmlEntitiesInOptions(asRecordClone(params.arguments)),
|
|
391
|
+
...(inputResponses ? { inputResponses } : {}),
|
|
392
|
+
...(typeof params.requestState === "string"
|
|
393
|
+
? { requestState: params.requestState }
|
|
394
|
+
: {}),
|
|
395
|
+
};
|
|
310
396
|
const access = await resolveMcpToolAccess(TOOLS, name, requestedArgs);
|
|
311
397
|
if (!access.available) {
|
|
312
398
|
throw new PmCliError(`pm MCP tool "${name}" is unavailable in the ${access.profile} profile.`, 64);
|
|
@@ -339,10 +425,70 @@ async function handleToolCall(paramsInput) {
|
|
|
339
425
|
// cwd is applied inside the serialized activation cycle (see withActiveExtensions),
|
|
340
426
|
// so the chdir/restore is exclusive per request and cannot race a concurrent caller.
|
|
341
427
|
const result = await handler(args);
|
|
428
|
+
void emitMcpChangeNotifications(action);
|
|
342
429
|
return resultContent(result, warnings, args.tokenAccounting === true);
|
|
343
430
|
}, { probesEnabled: workspaceIdentity?.probes_enabled });
|
|
344
431
|
});
|
|
345
432
|
}
|
|
433
|
+
/** Open one modern subscription through a concrete transport-owned sink. */
|
|
434
|
+
export async function openMcpSubscription(input) {
|
|
435
|
+
if ((typeof input.request.id !== "string" &&
|
|
436
|
+
typeof input.request.id !== "number") ||
|
|
437
|
+
input.request.method !== "subscriptions/listen") {
|
|
438
|
+
throw new PmMcpProtocolError("Invalid MCP subscriptions/listen request", PM_MCP_ERROR_CODES.invalidParams, { required: ["id", "method", "params.notifications"] });
|
|
439
|
+
}
|
|
440
|
+
resolveMcpRequestContext(input.request.params);
|
|
441
|
+
const key = input.key ?? input.request.id;
|
|
442
|
+
if (PM_MCP_SUBSCRIPTIONS.has(key)) {
|
|
443
|
+
throw new PmMcpProtocolError("MCP subscription id is already active", PM_MCP_ERROR_CODES.invalidParams, { subscriptionId: input.request.id });
|
|
444
|
+
}
|
|
445
|
+
const registry = createMcpSubscriptionRegistry();
|
|
446
|
+
await registry.open({
|
|
447
|
+
id: input.request.id,
|
|
448
|
+
notifications: input.request.params?.notifications,
|
|
449
|
+
sink: input.sink,
|
|
450
|
+
});
|
|
451
|
+
PM_MCP_SUBSCRIPTIONS.set(key, { id: input.request.id, registry });
|
|
452
|
+
}
|
|
453
|
+
/** Gracefully close one active subscription by its request identifier. */
|
|
454
|
+
export function closeMcpSubscription(id, key = id) {
|
|
455
|
+
const subscription = PM_MCP_SUBSCRIPTIONS.get(key);
|
|
456
|
+
if (!subscription || subscription.id !== id)
|
|
457
|
+
return undefined;
|
|
458
|
+
PM_MCP_SUBSCRIPTIONS.delete(key);
|
|
459
|
+
return subscription.registry.close(id);
|
|
460
|
+
}
|
|
461
|
+
function closeStdioMcpSubscriptions() {
|
|
462
|
+
const closed = [];
|
|
463
|
+
for (const [key, subscription] of PM_MCP_SUBSCRIPTIONS) {
|
|
464
|
+
if (key !== subscription.id)
|
|
465
|
+
continue;
|
|
466
|
+
const result = closeMcpSubscription(subscription.id, key);
|
|
467
|
+
if (result)
|
|
468
|
+
closed.push({ id: subscription.id, result });
|
|
469
|
+
}
|
|
470
|
+
return closed;
|
|
471
|
+
}
|
|
472
|
+
/** Resolve the current workspace-enriched tool schema for HTTP header checks. */
|
|
473
|
+
export async function resolveMcpToolSchemaForRequest(request) {
|
|
474
|
+
if (request.method !== "tools/call")
|
|
475
|
+
return undefined;
|
|
476
|
+
const name = request.params?.name;
|
|
477
|
+
if (typeof name !== "string")
|
|
478
|
+
return undefined;
|
|
479
|
+
const surface = await resolveMcpToolSurface(TOOLS, requestWorkspaceArgs(request.params));
|
|
480
|
+
return surface.tools.find((tool) => tool.name === name)?.inputSchema;
|
|
481
|
+
}
|
|
482
|
+
/** Preserve MCP tool-result error semantics for non-protocol adapter failures. */
|
|
483
|
+
export function buildMcpToolCallErrorResult(request, error) {
|
|
484
|
+
if (request.method !== "tools/call" || error instanceof PmMcpProtocolError) {
|
|
485
|
+
return undefined;
|
|
486
|
+
}
|
|
487
|
+
const content = errorContent(error);
|
|
488
|
+
return hasMcpProtocolVersionMetadata(request)
|
|
489
|
+
? buildMcpCompleteResult(content, PM_MCP_SERVER_INFO)
|
|
490
|
+
: content;
|
|
491
|
+
}
|
|
346
492
|
function requestWorkspaceArgs(params) {
|
|
347
493
|
const paramsRecord = asRecordClone(params);
|
|
348
494
|
return asRecordClone(paramsRecord.arguments ?? paramsRecord);
|
|
@@ -389,6 +535,16 @@ async function readWorkspaceResource(uri, params) {
|
|
|
389
535
|
],
|
|
390
536
|
};
|
|
391
537
|
}
|
|
538
|
+
async function loadRequestSkillRegistry(params) {
|
|
539
|
+
const args = requestWorkspaceArgs(params);
|
|
540
|
+
const cwd = typeof args.cwd === "string" ? args.cwd : process.cwd();
|
|
541
|
+
const workspaceRoot = resolveWorkspaceRoot(resolvePmRoot(cwd, typeof args.path === "string" ? args.path : undefined));
|
|
542
|
+
return PmMcpSkillRegistry.load({
|
|
543
|
+
packageRoot: resolvePmPackageRoot(),
|
|
544
|
+
workspaceRoot,
|
|
545
|
+
packageVersion: PM_MCP_SERVER_VERSION,
|
|
546
|
+
});
|
|
547
|
+
}
|
|
392
548
|
function renderWorkflowPrompt(params) {
|
|
393
549
|
const paramsRecord = asRecordClone(params);
|
|
394
550
|
const name = readRequiredString(paramsRecord, "name");
|
|
@@ -411,62 +567,367 @@ function renderWorkflowPrompt(params) {
|
|
|
411
567
|
messages: [{ role: "user", content: { type: "text", text } }],
|
|
412
568
|
};
|
|
413
569
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
570
|
+
const LEGACY_MCP_ADAPTER = new LegacyMcpAdapter({
|
|
571
|
+
serverInfo: PM_MCP_SERVER_INFO,
|
|
572
|
+
capabilities: PM_MCP_SERVER_CAPABILITIES,
|
|
573
|
+
instructions: PM_MCP_INSTRUCTIONS,
|
|
574
|
+
parseClientInfo: readMcpClientInfo,
|
|
575
|
+
listTools: async (params) => ({
|
|
576
|
+
tools: (await resolveMcpToolSurface(TOOLS, requestWorkspaceArgs(params)))
|
|
577
|
+
.tools,
|
|
578
|
+
}),
|
|
579
|
+
callTool: handleToolCall,
|
|
580
|
+
listResources: () => ({ resources: PM_MCP_RESOURCE_CONTRACTS }),
|
|
581
|
+
readResource: (params) => readWorkspaceResource(readRequiredString(asRecordClone(params), "uri"), params),
|
|
582
|
+
listPrompts: () => ({
|
|
583
|
+
prompts: PM_MCP_PROMPT_CONTRACTS.map((prompt) => ({
|
|
584
|
+
name: prompt.name,
|
|
585
|
+
description: prompt.description,
|
|
586
|
+
arguments: prompt.arguments,
|
|
587
|
+
})),
|
|
588
|
+
}),
|
|
589
|
+
getPrompt: renderWorkflowPrompt,
|
|
590
|
+
});
|
|
591
|
+
function deterministicMcpTools(tools) {
|
|
592
|
+
return tools
|
|
593
|
+
.map((tool) => ({
|
|
594
|
+
...tool,
|
|
595
|
+
inputSchema: validateMcpJsonSchema(tool.inputSchema),
|
|
596
|
+
}))
|
|
597
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
598
|
+
}
|
|
599
|
+
function mcpTaskPrincipal(requestContext) {
|
|
600
|
+
return requestContext.clientInfo
|
|
601
|
+
? `${requestContext.clientInfo.name}@${requestContext.clientInfo.version}`
|
|
602
|
+
: "anonymous-stdio";
|
|
603
|
+
}
|
|
604
|
+
function mcpTaskStore() {
|
|
605
|
+
return createMcpTaskStore({
|
|
606
|
+
pmRoot: resolvePmRoot(process.cwd()),
|
|
607
|
+
owner: "pm-mcp-task-provider",
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
function shouldCreateMcpTask(params, requestContext) {
|
|
611
|
+
if (!hasMcpClientExtension(requestContext, PM_MCP_TASKS_EXTENSION)) {
|
|
612
|
+
return false;
|
|
418
613
|
}
|
|
419
|
-
|
|
420
|
-
|
|
614
|
+
const requestParams = asRecordClone(params);
|
|
615
|
+
const name = requestParams.name;
|
|
616
|
+
const args = asRecordClone(requestParams.arguments);
|
|
617
|
+
if (PM_MCP_DIRECT_TASK_TOOLS.has(name))
|
|
618
|
+
return true;
|
|
619
|
+
if (name === "pm_test" &&
|
|
620
|
+
(args.subcommand === "run" ||
|
|
621
|
+
(isMcpRecord(args.options) && args.options.subcommand === "run"))) {
|
|
622
|
+
return true;
|
|
421
623
|
}
|
|
422
|
-
if (
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
624
|
+
if (name !== "pm_run")
|
|
625
|
+
return false;
|
|
626
|
+
return (typeof args.action === "string" && PM_MCP_RUN_TASK_ACTIONS.has(args.action));
|
|
627
|
+
}
|
|
628
|
+
const PENDING_MCP_TASKS = new Map();
|
|
629
|
+
async function executeMcpTask(execution, inputResponses) {
|
|
630
|
+
const params = {
|
|
631
|
+
...execution.params,
|
|
632
|
+
...(inputResponses ? { inputResponses } : {}),
|
|
633
|
+
...(execution.requestState ? { requestState: execution.requestState } : {}),
|
|
634
|
+
};
|
|
635
|
+
try {
|
|
636
|
+
const result = await handleToolCall(params, execution.context.clientInfo);
|
|
637
|
+
await execution.store.complete(execution.taskId, execution.principal, buildMcpCompleteResult(result, PM_MCP_SERVER_INFO));
|
|
638
|
+
PENDING_MCP_TASKS.delete(execution.taskId);
|
|
639
|
+
}
|
|
640
|
+
catch (error) {
|
|
641
|
+
if (error instanceof PmMcpInputRequiredError) {
|
|
642
|
+
execution.requestState = error.requestState;
|
|
643
|
+
await execution.store.requireInput({
|
|
644
|
+
taskId: execution.taskId,
|
|
645
|
+
principal: execution.principal,
|
|
646
|
+
requestContext: execution.context,
|
|
647
|
+
inputRequests: error.inputRequests,
|
|
648
|
+
statusMessage: "Task requires additional client input.",
|
|
649
|
+
});
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
if (error instanceof PmMcpProtocolError) {
|
|
653
|
+
await execution.store.fail(execution.taskId, execution.principal, {
|
|
654
|
+
code: error.code,
|
|
655
|
+
message: error.message,
|
|
656
|
+
data: error.data,
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
await execution.store.complete(execution.taskId, execution.principal, buildMcpCompleteResult(errorContent(error), PM_MCP_SERVER_INFO));
|
|
661
|
+
}
|
|
662
|
+
PENDING_MCP_TASKS.delete(execution.taskId);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
async function settleMcpTaskExecution(taskId, execution) {
|
|
666
|
+
try {
|
|
667
|
+
await execution;
|
|
668
|
+
}
|
|
669
|
+
catch {
|
|
670
|
+
// Persistence failures can outlive the request that created the detached
|
|
671
|
+
// execution. Keep them from becoming process-level unhandled rejections;
|
|
672
|
+
// the durable task record remains available for TTL-based recovery.
|
|
673
|
+
PENDING_MCP_TASKS.delete(taskId);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function scheduleMcpTaskExecution(execution, inputResponses) {
|
|
677
|
+
void settleMcpTaskExecution(execution.taskId, executeMcpTask(execution, inputResponses));
|
|
678
|
+
}
|
|
679
|
+
async function createMcpTaskForToolCall(params, requestContext) {
|
|
680
|
+
const store = mcpTaskStore();
|
|
681
|
+
const principal = mcpTaskPrincipal(requestContext);
|
|
682
|
+
const task = await store.create({
|
|
683
|
+
principal,
|
|
684
|
+
statusMessage: "pm operation accepted for asynchronous execution.",
|
|
685
|
+
});
|
|
686
|
+
const execution = {
|
|
687
|
+
context: requestContext,
|
|
688
|
+
params: asRecordClone(params),
|
|
689
|
+
principal,
|
|
690
|
+
store,
|
|
691
|
+
taskId: task.taskId,
|
|
692
|
+
};
|
|
693
|
+
PENDING_MCP_TASKS.set(task.taskId, execution);
|
|
694
|
+
scheduleMcpTaskExecution(execution);
|
|
695
|
+
return attachMcpServerInfo(task, PM_MCP_SERVER_INFO);
|
|
696
|
+
}
|
|
697
|
+
async function dispatchMcpTaskMethod(request, requestContext) {
|
|
698
|
+
if (!hasMcpClientExtension(requestContext, PM_MCP_TASKS_EXTENSION)) {
|
|
699
|
+
throw new PmMcpProtocolError("Missing required client capability", PM_MCP_ERROR_CODES.missingRequiredClientCapability, {
|
|
700
|
+
requiredCapabilities: {
|
|
701
|
+
extensions: { [PM_MCP_TASKS_EXTENSION]: {} },
|
|
430
702
|
},
|
|
431
|
-
|
|
432
|
-
instructions: "You have access to native pm CLI tools for git-based project management. " +
|
|
433
|
-
"Use pm_next to pick the next actionable item, or pm_context or pm_search before creating new work. " +
|
|
434
|
-
"Prefer narrow tools (pm_next, pm_context, pm_list, pm_get, pm_search, pm_events, pm_create, pm_mutate, pm_copy, pm_focus, pm_update, pm_append, pm_claim, pm_release, pm_close, pm_comments, pm_files, pm_docs, pm_notes, pm_learnings, pm_deps, pm_graph, pm_test, pm_validate, pm_health, pm_contracts, pm_schema, pm_profile, pm_config, pm_plan) over pm_run when they cover the operation. " +
|
|
435
|
-
"Use pm_plan for agent harness Plan workflows: it provides Codex/Claude/Cursor-style planning with durable steps, dependencies, decisions, discoveries, validation, and materialization. " +
|
|
436
|
-
"Use pm_schema and pm_config for workspace configuration: pm_schema manages custom item types/statuses and pm_config reads or writes settings keys. " +
|
|
437
|
-
"Use pm_run with an explicit action for active package-owned operations, plus activity, aggregate, history, stats, test-all, and gc. " +
|
|
438
|
-
"Use history-redact for audited history-stream redaction workflows, history-repair to re-anchor a drifted history chain, and history-compact to checkpoint/prune long history streams while preserving replay integrity. " +
|
|
439
|
-
"Agent harness and model provenance are detected automatically; pass author only for an intentional identity override. " +
|
|
440
|
-
"Do not pass path during real repository tracking — only pass path for sandbox or test runs.",
|
|
441
|
-
};
|
|
703
|
+
});
|
|
442
704
|
}
|
|
705
|
+
const params = asRecordClone(request.params);
|
|
706
|
+
const taskId = readRequiredString(params, "taskId");
|
|
707
|
+
const principal = mcpTaskPrincipal(requestContext);
|
|
708
|
+
const store = mcpTaskStore();
|
|
709
|
+
if (request.method === "tasks/get") {
|
|
710
|
+
return buildMcpCompleteResult(await store.get(taskId, principal), PM_MCP_SERVER_INFO);
|
|
711
|
+
}
|
|
712
|
+
if (request.method === "tasks/update") {
|
|
713
|
+
const update = await store.update(taskId, principal, params.inputResponses);
|
|
714
|
+
const execution = PENDING_MCP_TASKS.get(taskId);
|
|
715
|
+
if (execution &&
|
|
716
|
+
update.acceptedKeys.length > 0 &&
|
|
717
|
+
update.remainingKeys.length === 0) {
|
|
718
|
+
scheduleMcpTaskExecution(execution, await store.takeInputResponses(taskId, principal));
|
|
719
|
+
}
|
|
720
|
+
return buildMcpCompleteResult({}, PM_MCP_SERVER_INFO);
|
|
721
|
+
}
|
|
722
|
+
await store.cancel(taskId, principal);
|
|
723
|
+
PENDING_MCP_TASKS.delete(taskId);
|
|
724
|
+
return buildMcpCompleteResult({}, PM_MCP_SERVER_INFO);
|
|
725
|
+
}
|
|
726
|
+
async function dispatchModernToolMethod(request, requestContext, clientInfo) {
|
|
443
727
|
if (request.method === "tools/list") {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
728
|
+
const surface = await resolveMcpToolSurface(TOOLS, requestWorkspaceArgs(request.params));
|
|
729
|
+
return buildMcpCompleteResult(withMcpCachePolicy({
|
|
730
|
+
tools: hasCompatiblePmMcpAppsCapability(requestContext)
|
|
731
|
+
? decoratePmMcpToolsWithApps(deterministicMcpTools(surface.tools))
|
|
732
|
+
: deterministicMcpTools(surface.tools),
|
|
733
|
+
}, PM_MCP_CACHE_POLICIES.tools), PM_MCP_SERVER_INFO);
|
|
734
|
+
}
|
|
735
|
+
if (shouldCreateMcpTask(request.params, requestContext)) {
|
|
736
|
+
return createMcpTaskForToolCall(request.params, requestContext);
|
|
737
|
+
}
|
|
738
|
+
try {
|
|
739
|
+
return buildMcpCompleteResult(await handleToolCall(request.params, clientInfo), PM_MCP_SERVER_INFO);
|
|
447
740
|
}
|
|
448
|
-
|
|
449
|
-
|
|
741
|
+
catch (error) {
|
|
742
|
+
if (!(error instanceof PmMcpInputRequiredError))
|
|
743
|
+
throw error;
|
|
744
|
+
return buildMcpInputRequiredResult({
|
|
745
|
+
requestContext,
|
|
746
|
+
serverInfo: PM_MCP_SERVER_INFO,
|
|
747
|
+
inputRequests: error.inputRequests,
|
|
748
|
+
requestState: error.requestState,
|
|
749
|
+
});
|
|
450
750
|
}
|
|
751
|
+
}
|
|
752
|
+
async function dispatchModernResourceMethod(request, requestContext) {
|
|
451
753
|
if (request.method === "resources/list") {
|
|
452
|
-
|
|
754
|
+
const resources = [
|
|
755
|
+
...PM_MCP_RESOURCE_CONTRACTS,
|
|
756
|
+
...(hasCompatiblePmMcpAppsCapability(requestContext)
|
|
757
|
+
? PM_MCP_APP_CONTRACTS.map((contract) => ({
|
|
758
|
+
uri: contract.uri,
|
|
759
|
+
name: contract.name,
|
|
760
|
+
description: contract.description,
|
|
761
|
+
mimeType: PM_MCP_APP_MIME_TYPE,
|
|
762
|
+
_meta: { ui: contract.resourceMeta },
|
|
763
|
+
}))
|
|
764
|
+
: []),
|
|
765
|
+
].sort((left, right) => left.uri.localeCompare(right.uri));
|
|
766
|
+
return buildMcpCompleteResult(withMcpCachePolicy({ resources }, PM_MCP_CACHE_POLICIES.resources), PM_MCP_SERVER_INFO);
|
|
453
767
|
}
|
|
454
|
-
if (request.method === "resources/
|
|
455
|
-
return
|
|
768
|
+
if (request.method === "resources/templates/list") {
|
|
769
|
+
return buildMcpCompleteResult(withMcpCachePolicy({ resourceTemplates: [] }, PM_MCP_CACHE_POLICIES.resources), PM_MCP_SERVER_INFO);
|
|
456
770
|
}
|
|
457
|
-
|
|
458
|
-
|
|
771
|
+
try {
|
|
772
|
+
const uri = readRequiredString(asRecordClone(request.params), "uri");
|
|
773
|
+
const app = findPmMcpAppByUri(uri);
|
|
774
|
+
let resource;
|
|
775
|
+
if (app) {
|
|
776
|
+
if (!hasPmMcpAppsCapability(requestContext)) {
|
|
777
|
+
throw new PmMcpProtocolError("MCP App resource requires negotiated client capability", PM_MCP_ERROR_CODES.missingRequiredClientCapability, {
|
|
778
|
+
requiredCapabilities: {
|
|
779
|
+
extensions: {
|
|
780
|
+
[PM_MCP_APPS_EXTENSION]: PM_MCP_APPS_SERVER_CAPABILITY,
|
|
781
|
+
},
|
|
782
|
+
},
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
resource = {
|
|
786
|
+
contents: [
|
|
787
|
+
{
|
|
788
|
+
uri,
|
|
789
|
+
mimeType: PM_MCP_APP_MIME_TYPE,
|
|
790
|
+
text: renderPmMcpAppHtml(app),
|
|
791
|
+
_meta: { ui: app.resourceMeta },
|
|
792
|
+
},
|
|
793
|
+
],
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
else if (uri.startsWith("skill://")) {
|
|
797
|
+
assertPmMcpSkillsCapability(requestContext);
|
|
798
|
+
resource = {
|
|
799
|
+
...(await loadRequestSkillRegistry(request.params)).read(uri),
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
resource = await readWorkspaceResource(uri, request.params);
|
|
804
|
+
}
|
|
805
|
+
return buildMcpCompleteResult(withMcpCachePolicy(resource, PM_MCP_CACHE_POLICIES.resource), PM_MCP_SERVER_INFO);
|
|
806
|
+
}
|
|
807
|
+
catch (error) {
|
|
808
|
+
if (!(error instanceof PmCliError) ||
|
|
809
|
+
!error.message.startsWith("Unknown pm MCP resource:")) {
|
|
810
|
+
throw error;
|
|
811
|
+
}
|
|
812
|
+
throw new PmMcpProtocolError(error.message, PM_MCP_ERROR_CODES.invalidParams, { field: "uri" });
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
/** Treat an incompatible optional Apps declaration as absent during discovery. */
|
|
816
|
+
function hasCompatiblePmMcpAppsCapability(requestContext) {
|
|
817
|
+
try {
|
|
818
|
+
return hasPmMcpAppsCapability(requestContext);
|
|
819
|
+
}
|
|
820
|
+
catch (error) {
|
|
821
|
+
if (error instanceof PmMcpProtocolError)
|
|
822
|
+
return false;
|
|
823
|
+
throw error;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/** Validate Skills pagination inputs before handing them to the SDK registry. */
|
|
827
|
+
function readSkillPageOptions(params) {
|
|
828
|
+
if (params.cursor !== undefined && typeof params.cursor !== "string") {
|
|
829
|
+
throw new PmMcpProtocolError("Skills cursor must be a string", PM_MCP_ERROR_CODES.invalidParams, { field: "cursor" });
|
|
830
|
+
}
|
|
831
|
+
if (params.limit !== undefined && typeof params.limit !== "number") {
|
|
832
|
+
throw new PmMcpProtocolError("Skills limit must be a number", PM_MCP_ERROR_CODES.invalidParams, { field: "limit" });
|
|
833
|
+
}
|
|
834
|
+
return {
|
|
835
|
+
...(typeof params.cursor === "string" ? { cursor: params.cursor } : {}),
|
|
836
|
+
...(typeof params.limit === "number" ? { limit: params.limit } : {}),
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
async function dispatchModernSkillMethod(request, requestContext) {
|
|
840
|
+
const directoryRead = request.method === "resources/directory/read";
|
|
841
|
+
assertPmMcpSkillsCapability(requestContext, directoryRead);
|
|
842
|
+
const params = asRecordClone(request.params);
|
|
843
|
+
const registry = await loadRequestSkillRegistry(request.params);
|
|
844
|
+
let result;
|
|
845
|
+
if (request.method === "skills/list") {
|
|
846
|
+
result = { ...registry.list(readSkillPageOptions(params)) };
|
|
847
|
+
}
|
|
848
|
+
else if (request.method === "skills/get") {
|
|
849
|
+
result = { skill: registry.get(readRequiredString(params, "uri")) };
|
|
850
|
+
}
|
|
851
|
+
else {
|
|
852
|
+
result = {
|
|
853
|
+
...registry.readDirectory(readRequiredString(params, "uri"), readSkillPageOptions(params)),
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
return buildMcpCompleteResult(withMcpCachePolicy(result, PM_MCP_CACHE_POLICIES.resource), PM_MCP_SERVER_INFO);
|
|
857
|
+
}
|
|
858
|
+
function dispatchModernPromptMethod(request) {
|
|
859
|
+
const result = request.method === "prompts/list"
|
|
860
|
+
? withMcpCachePolicy({
|
|
459
861
|
prompts: PM_MCP_PROMPT_CONTRACTS.map((prompt) => ({
|
|
460
862
|
name: prompt.name,
|
|
461
863
|
description: prompt.description,
|
|
462
864
|
arguments: prompt.arguments,
|
|
463
|
-
})),
|
|
464
|
-
}
|
|
865
|
+
})).sort((left, right) => left.name.localeCompare(right.name)),
|
|
866
|
+
}, PM_MCP_CACHE_POLICIES.prompts)
|
|
867
|
+
: renderWorkflowPrompt(request.params);
|
|
868
|
+
return buildMcpCompleteResult(result, PM_MCP_SERVER_INFO);
|
|
869
|
+
}
|
|
870
|
+
/** Dispatch one validated stateless request through the modern surface. */
|
|
871
|
+
async function dispatchModernMcpRequest(request, meta) {
|
|
872
|
+
const requestContext = resolveMcpRequestContext(request.params);
|
|
873
|
+
const clientInfo = readMcpClientInfo(meta[PM_MCP_META_KEYS.clientInfo]);
|
|
874
|
+
if (request.method === "server/discover") {
|
|
875
|
+
return buildMcpDiscoverResult({
|
|
876
|
+
serverInfo: PM_MCP_SERVER_INFO,
|
|
877
|
+
capabilities: PM_MCP_SERVER_CAPABILITIES,
|
|
878
|
+
instructions: PM_MCP_INSTRUCTIONS,
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
if (request.method === "ping") {
|
|
882
|
+
// The preceding match is an mcp-deprecation-negative-control for modern callers.
|
|
883
|
+
throw new PmMcpProtocolError("MCP method not found: ping", -32601, {
|
|
884
|
+
removedIn: PM_MCP_PROTOCOL_VERSION,
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
if (PM_MCP_SKILL_METHODS.has(request.method ?? "")) {
|
|
888
|
+
return dispatchModernSkillMethod(request, requestContext);
|
|
889
|
+
}
|
|
890
|
+
if (request.method === "tasks/get" ||
|
|
891
|
+
request.method === "tasks/update" ||
|
|
892
|
+
request.method === "tasks/cancel") {
|
|
893
|
+
return dispatchMcpTaskMethod(request, requestContext);
|
|
894
|
+
}
|
|
895
|
+
if (request.method === "tools/list" || request.method === "tools/call") {
|
|
896
|
+
return dispatchModernToolMethod(request, requestContext, clientInfo);
|
|
897
|
+
}
|
|
898
|
+
if (request.method === "resources/list" ||
|
|
899
|
+
request.method === "resources/templates/list" ||
|
|
900
|
+
request.method === "resources/read") {
|
|
901
|
+
return dispatchModernResourceMethod(request, requestContext);
|
|
465
902
|
}
|
|
466
|
-
if (request.method === "prompts/get") {
|
|
467
|
-
return
|
|
903
|
+
if (request.method === "prompts/list" || request.method === "prompts/get") {
|
|
904
|
+
return dispatchModernPromptMethod(request);
|
|
905
|
+
}
|
|
906
|
+
throw new PmMcpProtocolError(`MCP method not found: ${request.method ?? "(missing)"}`, -32601);
|
|
907
|
+
}
|
|
908
|
+
/** Implements handle request for the public runtime surface of this module. */
|
|
909
|
+
async function handleRequestInReproducibleContext(request) {
|
|
910
|
+
if (!request.id && request.method?.startsWith("notifications/")) {
|
|
911
|
+
return undefined;
|
|
912
|
+
}
|
|
913
|
+
if (hasMcpProtocolVersionMetadata(request)) {
|
|
914
|
+
const allowlist = (process.env.PM_MCP_BAGGAGE_ALLOWLIST ?? "")
|
|
915
|
+
.split(",")
|
|
916
|
+
.map((entry) => entry.trim())
|
|
917
|
+
.filter(Boolean);
|
|
918
|
+
return runWithMcpTraceContext(extractMcpTraceContext(request.params, { baggageAllowlist: allowlist }), () => dispatchModernMcpRequest(request, request.params._meta));
|
|
919
|
+
}
|
|
920
|
+
if (request.method === "initialize") {
|
|
921
|
+
// The preceding match is an mcp-legacy-boundary delegated to the isolated adapter.
|
|
922
|
+
return LEGACY_MCP_ADAPTER.initialize(request.params);
|
|
468
923
|
}
|
|
469
|
-
|
|
924
|
+
return LEGACY_MCP_ADAPTER.dispatch(request);
|
|
925
|
+
}
|
|
926
|
+
/** Return whether a request explicitly supplies the modern version metadata key. */
|
|
927
|
+
function hasMcpProtocolVersionMetadata(request) {
|
|
928
|
+
const meta = isMcpRecord(request.params) ? request.params._meta : undefined;
|
|
929
|
+
return (isMcpRecord(meta) &&
|
|
930
|
+
Object.prototype.hasOwnProperty.call(meta, PM_MCP_META_KEYS.protocolVersion));
|
|
470
931
|
}
|
|
471
932
|
/** Dispatch one MCP request under supported process-level reproducibility settings. */
|
|
472
933
|
export async function handleRequest(request) {
|
|
@@ -476,11 +937,47 @@ function writeResponse(id, payload) {
|
|
|
476
937
|
process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", id, result: payload })}\n`);
|
|
477
938
|
}
|
|
478
939
|
function writeError(id, error) {
|
|
479
|
-
const code = error instanceof
|
|
940
|
+
const code = error instanceof PmMcpProtocolError
|
|
941
|
+
? error.code
|
|
942
|
+
: error instanceof PmCliError
|
|
943
|
+
? error.exitCode
|
|
944
|
+
: -32603;
|
|
480
945
|
const message = error instanceof Error ? error.message : String(error);
|
|
481
|
-
const data = error instanceof
|
|
946
|
+
const data = error instanceof PmMcpProtocolError
|
|
947
|
+
? error.data
|
|
948
|
+
: error instanceof PmCliError
|
|
949
|
+
? error.context
|
|
950
|
+
: undefined;
|
|
482
951
|
process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", id, error: { code, message, data } })}\n`);
|
|
483
952
|
}
|
|
953
|
+
/** Write an MCP tool execution failure as a successful tool result envelope. */
|
|
954
|
+
function writeToolCallErrorResponse(request, error) {
|
|
955
|
+
if (request.method !== "tools/call" || error instanceof PmMcpProtocolError) {
|
|
956
|
+
return false;
|
|
957
|
+
}
|
|
958
|
+
writeResponse(request.id, buildMcpToolCallErrorResult(request, error));
|
|
959
|
+
return true;
|
|
960
|
+
}
|
|
961
|
+
async function handleStdioTransportControl(request) {
|
|
962
|
+
if (request.method === "subscriptions/listen") {
|
|
963
|
+
await openMcpSubscription({
|
|
964
|
+
request,
|
|
965
|
+
sink: (notification) => {
|
|
966
|
+
process.stdout.write(`${JSON.stringify(notification)}\n`);
|
|
967
|
+
},
|
|
968
|
+
});
|
|
969
|
+
return true;
|
|
970
|
+
}
|
|
971
|
+
if (request.method !== "notifications/cancelled")
|
|
972
|
+
return false;
|
|
973
|
+
const requestId = request.params?.requestId;
|
|
974
|
+
if (typeof requestId === "string" || typeof requestId === "number") {
|
|
975
|
+
const result = closeMcpSubscription(requestId);
|
|
976
|
+
if (result)
|
|
977
|
+
writeResponse(requestId, result);
|
|
978
|
+
}
|
|
979
|
+
return true;
|
|
980
|
+
}
|
|
484
981
|
// pm-3puw: parse one JSON-RPC line, dispatch it, and write the response. Kept
|
|
485
982
|
// as a standalone async unit so the stdio loop can enqueue it onto a serial
|
|
486
983
|
// queue (process lines in arrival order) and tests can drive it directly.
|
|
@@ -506,6 +1003,8 @@ async function processRpcLineWithHandler(line, requestHandler) {
|
|
|
506
1003
|
}
|
|
507
1004
|
const shouldRespond = Object.prototype.hasOwnProperty.call(request, "id");
|
|
508
1005
|
try {
|
|
1006
|
+
if (await handleStdioTransportControl(request))
|
|
1007
|
+
return;
|
|
509
1008
|
const result = await requestHandler(request);
|
|
510
1009
|
if (shouldRespond && result !== undefined) {
|
|
511
1010
|
writeResponse(request.id, result);
|
|
@@ -515,10 +1014,7 @@ async function processRpcLineWithHandler(line, requestHandler) {
|
|
|
515
1014
|
if (!shouldRespond) {
|
|
516
1015
|
return;
|
|
517
1016
|
}
|
|
518
|
-
if (request
|
|
519
|
-
writeResponse(request.id, errorContent(error));
|
|
520
|
-
}
|
|
521
|
-
else {
|
|
1017
|
+
if (!writeToolCallErrorResponse(request, error)) {
|
|
522
1018
|
writeError(request.id, error);
|
|
523
1019
|
}
|
|
524
1020
|
}
|
|
@@ -551,6 +1047,13 @@ export function startMcpServer() {
|
|
|
551
1047
|
rl.on("line", (line) => {
|
|
552
1048
|
void queue.enqueue(() => processLine(line));
|
|
553
1049
|
});
|
|
1050
|
+
rl.on("close", () => {
|
|
1051
|
+
void queue.enqueue(() => {
|
|
1052
|
+
for (const closed of closeStdioMcpSubscriptions()) {
|
|
1053
|
+
writeResponse(closed.id, closed.result);
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
});
|
|
554
1057
|
}
|
|
555
1058
|
// npm bin entries are symlinks (node_modules/.bin/pm-mcp -> dist/mcp/server.js),
|
|
556
1059
|
// so argv[1] must be realpath-resolved before comparing against this module's
|
|
@@ -582,14 +1085,19 @@ function readRuntimeTestHook(key) {
|
|
|
582
1085
|
/** Public contract for test only, shared by SDK and presentation-layer consumers. */
|
|
583
1086
|
export const _testOnly = {
|
|
584
1087
|
boundMcpClientProvenance,
|
|
1088
|
+
createMcpInputRequiredError: (input) => new PmMcpInputRequiredError(input),
|
|
1089
|
+
createMcpProtocolError: (...input) => new PmMcpProtocolError(...input),
|
|
585
1090
|
get closeManyOptionsFromFlat() {
|
|
586
1091
|
return readRuntimeTestHook("closeManyOptionsFromFlat");
|
|
587
1092
|
},
|
|
588
1093
|
detectUnexpectedOptionKeys,
|
|
589
1094
|
detectUnexpectedTopLevelKeys,
|
|
590
1095
|
collectMutationGuardWarnings,
|
|
1096
|
+
closeStdioMcpSubscriptions,
|
|
591
1097
|
errorContent,
|
|
592
|
-
|
|
1098
|
+
emitMcpChangeNotifications,
|
|
1099
|
+
expireMcpSubscriptionRecord: (id, key = id) => PM_MCP_SUBSCRIPTIONS.get(key).registry.close(id),
|
|
1100
|
+
getMcpClientInfo: () => LEGACY_MCP_ADAPTER.getClientInfo(),
|
|
593
1101
|
get extensionOptionsFromArgs() {
|
|
594
1102
|
return readRuntimeTestHook("extensionOptionsFromArgs");
|
|
595
1103
|
},
|
|
@@ -600,7 +1108,12 @@ export const _testOnly = {
|
|
|
600
1108
|
return readRuntimeTestHook("mutationListOptions");
|
|
601
1109
|
},
|
|
602
1110
|
nearestDeclaredKey,
|
|
1111
|
+
mcpTaskPrincipal,
|
|
603
1112
|
resultContent,
|
|
1113
|
+
resolveMcpRequestContext,
|
|
1114
|
+
shouldCreateMcpTask,
|
|
1115
|
+
settleMcpTaskExecution,
|
|
1116
|
+
subscriptionCount: () => PM_MCP_SUBSCRIPTIONS.size,
|
|
604
1117
|
get normalizeActionName() {
|
|
605
1118
|
return readRuntimeTestHook("normalizeActionName");
|
|
606
1119
|
},
|
|
@@ -649,4 +1162,4 @@ if (isInvokedAsMcpMainModule(process.argv[1], import.meta.url)) {
|
|
|
649
1162
|
}
|
|
650
1163
|
/* c8 ignore stop */
|
|
651
1164
|
//# sourceMappingURL=server.js.map
|
|
652
|
-
//# debugId=
|
|
1165
|
+
//# debugId=77067047-62fc-54e8-9047-ad30580d6125
|