Skip to content

fix(platform-mcp): enhance error logging for tools, prompts, and reso… - #3353

Merged
Romakita merged 1 commit into
productionfrom
feat-mcp-error-management
May 7, 2026
Merged

fix(platform-mcp): enhance error logging for tools, prompts, and reso…#3353
Romakita merged 1 commit into
productionfrom
feat-mcp-error-management

Conversation

@Romakita

@Romakita Romakita commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Standardized MCP error responses with derived error codes, status codes, request IDs, and diagnostic metadata.
  • Improvements

    • MCP server can surface metadata (title, description, website, icons) and accept server options.
    • CLI "apply" output now returns concrete artifact-file mappings; workflows now require reading all listed concrete paths.
  • Documentation

    • Reorganized and expanded agent/command/workflow docs for onboarding, apply/ff/new/sync/archive workflows.
  • Tests

    • Added tests validating MCP error-wrapping behavior for tools, resources, and prompts.

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7ac22690-08bc-48f0-8dfc-3b08ecc0aaba

📥 Commits

Reviewing files that changed from the base of the PR and between 64827ea and ff1b5fc.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (48)
  • .agents/skills/openspec-apply-change/SKILL.md
  • .agents/skills/openspec-archive-change/SKILL.md
  • .agents/skills/openspec-explore/SKILL.md
  • .agents/skills/openspec-propose/SKILL.md
  • .claude/AGENTS.md
  • .claude/commands/opsx/apply.md
  • .claude/commands/opsx/bulk-archive.md
  • .claude/commands/opsx/continue.md
  • .claude/commands/opsx/explore.md
  • .claude/commands/opsx/ff.md
  • .claude/commands/opsx/new.md
  • .claude/commands/opsx/onboard.md
  • .claude/commands/opsx/sync.md
  • .claude/commands/opsx/verify.md
  • .claude/skills
  • .claude/skills/openspec-apply-change/SKILL.md
  • .claude/skills/openspec-bulk-archive-change/SKILL.md
  • .claude/skills/openspec-continue-change/SKILL.md
  • .claude/skills/openspec-ff-change/SKILL.md
  • .claude/skills/openspec-new-change/SKILL.md
  • .claude/skills/openspec-onboard/SKILL.md
  • .claude/skills/openspec-propose/SKILL.md
  • .claude/skills/openspec-sync-specs/SKILL.md
  • .claude/skills/openspec-verify-change/SKILL.md
  • .codex/AGENTS.md
  • .codex/skills
  • .codex/skills/migrate-tsed-functional-api/SKILL.md
  • .codex/skills/openspec-archive-change/SKILL.md
  • .codex/skills/openspec-bulk-archive-change/SKILL.md
  • .codex/skills/openspec-continue-change/SKILL.md
  • .codex/skills/openspec-explore/SKILL.md
  • .codex/skills/openspec-ff-change/SKILL.md
  • .codex/skills/openspec-new-change/SKILL.md
  • .codex/skills/openspec-onboard/SKILL.md
  • .codex/skills/openspec-sync-specs/SKILL.md
  • .codex/skills/openspec-verify-change/SKILL.md
  • docs/docs/mcp.md
  • openspec/project.md
  • packages/platform/platform-mcp/package.json
  • packages/platform/platform-mcp/src/fn/definePrompt.spec.ts
  • packages/platform/platform-mcp/src/fn/definePrompt.ts
  • packages/platform/platform-mcp/src/fn/defineResource.spec.ts
  • packages/platform/platform-mcp/src/fn/defineResource.ts
  • packages/platform/platform-mcp/src/fn/defineTool.spec.ts
  • packages/platform/platform-mcp/src/fn/defineTool.ts
  • packages/platform/platform-mcp/src/interfaces/PlatformMcpSettings.ts
  • packages/platform/platform-mcp/src/services/McpServerFactory.ts
  • reports/jsdoc/platform-mcp.md

Walkthrough

This PR centralizes MCP error handling (wrapping tool/resource/prompt handlers to return structured MCP fallback payloads with derived error codes and structured logs), extends MCP server settings, adds tests and docs; it also reorganizes and clarifies OpenSpec/OPSX skill and adapter documentation (version bumps to 1.3.1 and explicit contextFiles artifact→paths mapping).

Changes

MCP Error Handling Enhancement

Layer / File(s) Summary
Dependency & Interface
packages/platform/platform-mcp/package.json, packages/platform/platform-mcp/src/interfaces/PlatformMcpSettings.ts
Adds change-case dependency and extends PlatformMcpSettings with title, description, websiteUrl, icons, and serverOptions.
defineTool error wrapper
packages/platform/platform-mcp/src/fn/defineTool.ts
Derives MCP error code from thrown error.name/error.status using constantCase(), logs structured error payloads, and returns structuredCallTool fallback content.
defineResource error wrapper
packages/platform/platform-mcp/src/fn/defineResource.ts
Wraps resource handlers, normalizes thrown values, derives error codes when possible, logs MCP_RESOURCE_ERROR, and returns contents: [] plus _meta error payload.
definePrompt error wrapper
packages/platform/platform-mcp/src/fn/definePrompt.ts
Wraps prompt handlers to catch errors, derive prompt-specific error codes, log MCP_PROMPT_ERROR, and return GetPromptResult-shaped failure payloads with _meta.
Server Factory
packages/platform/platform-mcp/src/services/McpServerFactory.ts
Pass expanded server metadata (websiteUrl, description, icons, title) and optional serverOptions into McpServer constructor.
Tests & Docs
packages/platform/platform-mcp/src/fn/*.spec.ts, docs/docs/mcp.md, reports/jsdoc/platform-mcp.md
Adds/adjusts Vitest suites asserting wrapped error payload shapes and documents error handling, error-code derivation rules, and logging.

OpenSpec Skill & OPSX Documentation Restructuring

Layer / File(s) Summary
Shared Skill Version Updates
.agents/skills/openspec-apply-change/SKILL.md, .agents/skills/openspec-archive-change/SKILL.md, .agents/skills/openspec-explore/SKILL.md, .agents/skills/openspec-propose/SKILL.md
Bumped generatedBy metadata from 1.2.01.3.1; minor diagram/table reflows.
contextFiles Clarification
.agents/skills/openspec-apply-change/SKILL.md, .claude/commands/opsx/apply.md
Clarifies contextFiles is an artifact-ID → array of concrete file paths and instructs reading every listed path from apply-instructions output.
Insight Mapping & Diagrams
.agents/skills/openspec-explore/SKILL.md, .claude/commands/opsx/explore.md
Reformulated "Insight Type → Where to Capture" tables and adjusted ASCII state-machine diagram spacing.
Adapter AGENTS & Skill Pointers
.claude/AGENTS.md, .codex/AGENTS.md, .claude/skills, .codex/skills
Adds adapter notes and skill reference files pointing adapters to shared .agents/skills and documents where adapter-specific wrappers should live.
Claude OPSX Commands & Skills
.claude/commands/opsx/*, .claude/skills/*
Adds/updates OPSX command docs and Claude SKILL.md files (apply, continue, ff, new, archive, verify, etc.); some docs removed/emptied per diff.
Codex Adapter Skills
.codex/skills/*
Adds Codex adapter notes and skill pointers and includes migrated skill docs such as migrate-tsed-functional-api and various OpenSpec adapter skill docs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • tsedio/tsed#3349: Overlaps platform-mcp changes (definePrompt/defineResource/defineTool and tests).
  • tsedio/tsed#3244: Prior platform-mcp edits touching MCP behavior and settings.
  • tsedio/tsed#3336: Related platform tooling changes surfaced by vector search.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: enhancing error logging for MCP tools, prompts, and resources with structured error handling and metadata.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-mcp-error-management

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Romakita
Romakita force-pushed the feat-mcp-error-management branch from 515323b to 64827ea Compare May 7, 2026 08:04

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.claude/AGENTS.md:
- Line 5: The file is missing a final newline which triggers markdownlint rule
MD047; add a single trailing newline character at the end of the file (after the
line mentioning ".claude/skills" and ".claude/commands/opsx") so the file ends
with exactly one newline to satisfy the linter.

In @.codex/AGENTS.md:
- Line 5: The markdown file missing a trailing newline at the end; add a single
newline character at EOF so the line "The `.codex/skills` path is an adapter
that exposes those shared skills to Codex. Do not edit shared skill
implementations through this path. Keep Codex-specific prompt wrappers under
`.codex/prompts`." is followed by exactly one trailing newline to satisfy MD047
and CI linting.

In `@packages/platform/platform-mcp/src/fn/defineResource.ts`:
- Around line 108-127: The catch block in defineResource.ts dereferences er.name
and er.status directly and can crash for non-Error throws; normalize the thrown
value first (e.g. const safeErr = (er && typeof er === "object") ? er : {
message: String(er), name: undefined, status: undefined }) and then use safeErr
for building the code (constantCase(safeErr.name)), logging (logger()), and the
returned _meta fields (status_code: safeErr.status, error_name: safeErr.name,
message: safeErr.message, request_id: context().id, resource: opts.name) so the
handler is resilient to null/undefined or primitive throws.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d3ab3eea-e106-40fa-9210-06a6d1b6f480

📥 Commits

Reviewing files that changed from the base of the PR and between 2deb05b and 64827ea.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (48)
  • .agents/skills/openspec-apply-change/SKILL.md
  • .agents/skills/openspec-archive-change/SKILL.md
  • .agents/skills/openspec-explore/SKILL.md
  • .agents/skills/openspec-propose/SKILL.md
  • .claude/AGENTS.md
  • .claude/commands/opsx/apply.md
  • .claude/commands/opsx/bulk-archive.md
  • .claude/commands/opsx/continue.md
  • .claude/commands/opsx/explore.md
  • .claude/commands/opsx/ff.md
  • .claude/commands/opsx/new.md
  • .claude/commands/opsx/onboard.md
  • .claude/commands/opsx/sync.md
  • .claude/commands/opsx/verify.md
  • .claude/skills
  • .claude/skills/openspec-apply-change/SKILL.md
  • .claude/skills/openspec-bulk-archive-change/SKILL.md
  • .claude/skills/openspec-continue-change/SKILL.md
  • .claude/skills/openspec-ff-change/SKILL.md
  • .claude/skills/openspec-new-change/SKILL.md
  • .claude/skills/openspec-onboard/SKILL.md
  • .claude/skills/openspec-propose/SKILL.md
  • .claude/skills/openspec-sync-specs/SKILL.md
  • .claude/skills/openspec-verify-change/SKILL.md
  • .codex/AGENTS.md
  • .codex/skills
  • .codex/skills/migrate-tsed-functional-api/SKILL.md
  • .codex/skills/openspec-archive-change/SKILL.md
  • .codex/skills/openspec-bulk-archive-change/SKILL.md
  • .codex/skills/openspec-continue-change/SKILL.md
  • .codex/skills/openspec-explore/SKILL.md
  • .codex/skills/openspec-ff-change/SKILL.md
  • .codex/skills/openspec-new-change/SKILL.md
  • .codex/skills/openspec-onboard/SKILL.md
  • .codex/skills/openspec-sync-specs/SKILL.md
  • .codex/skills/openspec-verify-change/SKILL.md
  • docs/docs/mcp.md
  • openspec/project.md
  • packages/platform/platform-mcp/package.json
  • packages/platform/platform-mcp/src/fn/definePrompt.spec.ts
  • packages/platform/platform-mcp/src/fn/definePrompt.ts
  • packages/platform/platform-mcp/src/fn/defineResource.spec.ts
  • packages/platform/platform-mcp/src/fn/defineResource.ts
  • packages/platform/platform-mcp/src/fn/defineTool.spec.ts
  • packages/platform/platform-mcp/src/fn/defineTool.ts
  • packages/platform/platform-mcp/src/interfaces/PlatformMcpSettings.ts
  • packages/platform/platform-mcp/src/services/McpServerFactory.ts
  • reports/jsdoc/platform-mcp.md
💤 Files with no reviewable changes (27)
  • openspec/project.md
  • .codex/skills/openspec-explore/SKILL.md
  • .claude/skills/openspec-verify-change/SKILL.md
  • .claude/skills/openspec-propose/SKILL.md
  • .claude/commands/opsx/continue.md
  • .codex/skills/openspec-ff-change/SKILL.md
  • .claude/commands/opsx/verify.md
  • .claude/skills/openspec-bulk-archive-change/SKILL.md
  • .claude/commands/opsx/new.md
  • .claude/skills/openspec-ff-change/SKILL.md
  • .codex/skills/openspec-sync-specs/SKILL.md
  • .claude/skills/openspec-sync-specs/SKILL.md
  • .claude/commands/opsx/onboard.md
  • .codex/skills/openspec-verify-change/SKILL.md
  • .codex/skills/migrate-tsed-functional-api/SKILL.md
  • .claude/commands/opsx/sync.md
  • .claude/commands/opsx/bulk-archive.md
  • .codex/skills/openspec-bulk-archive-change/SKILL.md
  • .claude/skills/openspec-new-change/SKILL.md
  • .claude/skills/openspec-onboard/SKILL.md
  • .codex/skills/openspec-archive-change/SKILL.md
  • .codex/skills/openspec-continue-change/SKILL.md
  • .codex/skills/openspec-new-change/SKILL.md
  • .claude/skills/openspec-apply-change/SKILL.md
  • .claude/commands/opsx/ff.md
  • .codex/skills/openspec-onboard/SKILL.md
  • .claude/skills/openspec-continue-change/SKILL.md

Comment thread .claude/AGENTS.md

Shared OpenSpec skill logic is owned by `.agents/skills`.

The `.claude/skills` path is an adapter that exposes those shared skills to Claude. Do not edit shared skill implementations through this path. Keep Claude-specific command wrappers under `.claude/commands/opsx`. No newline at end of file

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add the final newline to resolve MD047.

Line 5 should end with a single trailing newline; otherwise markdownlint can report/fail this file.

Suggested fix
 The `.claude/skills` path is an adapter that exposes those shared skills to Claude. Do not edit shared skill implementations through this path. Keep Claude-specific command wrappers under `.claude/commands/opsx`.
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
The `.claude/skills` path is an adapter that exposes those shared skills to Claude. Do not edit shared skill implementations through this path. Keep Claude-specific command wrappers under `.claude/commands/opsx`.
The `.claude/skills` path is an adapter that exposes those shared skills to Claude. Do not edit shared skill implementations through this path. Keep Claude-specific command wrappers under `.claude/commands/opsx`.
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 5-5: Files should end with a single newline character

(MD047, single-trailing-newline)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.claude/AGENTS.md at line 5, The file is missing a final newline which
triggers markdownlint rule MD047; add a single trailing newline character at the
end of the file (after the line mentioning ".claude/skills" and
".claude/commands/opsx") so the file ends with exactly one newline to satisfy
the linter.

Comment thread .codex/AGENTS.md

Shared OpenSpec skill logic is owned by `.agents/skills`.

The `.codex/skills` path is an adapter that exposes those shared skills to Codex. Do not edit shared skill implementations through this path. Keep Codex-specific prompt wrappers under `.codex/prompts`. No newline at end of file

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add a trailing newline to satisfy markdownlint.

Line 5 appears to miss the required single trailing newline (MD047), which can fail lint checks in CI.

Suggested fix
 The `.codex/skills` path is an adapter that exposes those shared skills to Codex. Do not edit shared skill implementations through this path. Keep Codex-specific prompt wrappers under `.codex/prompts`.
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
The `.codex/skills` path is an adapter that exposes those shared skills to Codex. Do not edit shared skill implementations through this path. Keep Codex-specific prompt wrappers under `.codex/prompts`.
The `.codex/skills` path is an adapter that exposes those shared skills to Codex. Do not edit shared skill implementations through this path. Keep Codex-specific prompt wrappers under `.codex/prompts`.
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 5-5: Files should end with a single newline character

(MD047, single-trailing-newline)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.codex/AGENTS.md at line 5, The markdown file missing a trailing newline at
the end; add a single newline character at EOF so the line "The `.codex/skills`
path is an adapter that exposes those shared skills to Codex. Do not edit shared
skill implementations through this path. Keep Codex-specific prompt wrappers
under `.codex/prompts`." is followed by exactly one trailing newline to satisfy
MD047 and CI linting.

Comment thread packages/platform/platform-mcp/src/fn/defineResource.ts
…urces with structured payloads

- Added detailed error logging for tools, prompts, and resources, including `status_code`, `code`, `message`, `request_id`, and entity name in `_meta`.
- Updated `definePrompt`, `defineTool`, and `defineResource` to catch and log errors with structured data.
- Adjusted documentation and tests to align with the new error payload format.
- Added new types and support for MCP server metadata (`title`, `description`, `websiteUrl`, `icons`).
@Romakita
Romakita force-pushed the feat-mcp-error-management branch from 64827ea to ff1b5fc Compare May 7, 2026 08:47
@Romakita
Romakita merged commit 7ce81c8 into production May 7, 2026
1 of 10 checks passed
@Romakita
Romakita deleted the feat-mcp-error-management branch May 7, 2026 08:48
@Romakita

Romakita commented May 7, 2026

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 8.28.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant