Skip to content

Conversation

@rohitg00
Copy link
Contributor

@rohitg00 rohitg00 commented Oct 15, 2025

This pull request adds a comprehensive error handling and introspection system for the Motia MCP Server, along with utilities and middleware for validating requests and origins. The changes introduce structured error classes, core and origin validation middleware, new MCP service modules for tools and resources, and helper functions for building JSON-RPC responses. These improvements enhance the reliability, security, and introspectability of the Motia API.

Testing state in MCP Inspector

Screenshot 2025-10-15 at 14 13 33

Error Handling and Middleware

  • Introduced a base error class BaseError for consistent API error handling, including status codes, error codes, and metadata, with a toJSON method for API responses.
  • Added specific MCP error classes (e.g., MCPOriginError, MCPMethodNotFoundError, etc.) for granular error reporting in MCP operations.
  • Implemented coreMiddleware to catch and log errors, handle validation and custom errors, and return standardized error responses.
  • Added originValidationMiddleware to enforce MCP specification by validating the Origin header and preventing DNS rebinding attacks.

Motia Introspection and MCP Services

  • Created motia-introspection.ts, a singleton service for introspecting Motia internals (steps, flows, topics, endpoints) for use by MCP tools and resources.
  • Added MCP service exports (tools, resources, prompts, motia-introspection) to centralize domain-driven MCP logic.

MCP Tools and Resources

  • Defined a set of MCP tools (e.g., trigger_workflow, call_api, get_execution_logs, etc.) with input schemas for workflow automation and state management.
  • Implemented resource listing and reading functions, allowing MCP clients to discover and retrieve Motia steps, flows, topics, endpoints, and documentation (including a Markdown quick start guide).

JSON-RPC Response Utilities

  • Added helper functions to build standardized MCP JSON-RPC success and error responses, including standard error codes and common error responses.

@vercel
Copy link

vercel bot commented Oct 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
motia-docs Ready Ready Preview Comment Oct 15, 2025 8:45am
motia-ui Ready Ready Preview Comment Oct 15, 2025 8:45am

@github-actions
Copy link

⚠️ This PR is quite large (>1000 lines). Consider splitting it into smaller PRs for easier review.

@@ -0,0 +1,55 @@
import { ApiRouteConfig, Handlers } from 'motia'
import { z } from 'zod'
import { motiaIntrospection } from '../../src/services/mcp/motia-introspection'

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import motiaIntrospection.

Copilot Autofix

AI 21 days ago

To fix this issue, the unused import of motiaIntrospection from ../../src/services/mcp/motia-introspection should be removed from the top of the file playground/steps/mcp/init-introspection.step.ts. This change eliminates unnecessary code, improves readability, and may slightly improve startup performance by avoiding an unnecessary import. No other changes are needed as this import is not referenced elsewhere in the file.


Suggested changeset 1
playground/steps/mcp/init-introspection.step.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/playground/steps/mcp/init-introspection.step.ts b/playground/steps/mcp/init-introspection.step.ts
--- a/playground/steps/mcp/init-introspection.step.ts
+++ b/playground/steps/mcp/init-introspection.step.ts
@@ -1,6 +1,5 @@
 import { ApiRouteConfig, Handlers } from 'motia'
 import { z } from 'zod'
-import { motiaIntrospection } from '../../src/services/mcp/motia-introspection'
 
 /**
  * Initialization endpoint for MCP introspection service
EOF
@@ -1,6 +1,5 @@
import { ApiRouteConfig, Handlers } from 'motia'
import { z } from 'zod'
import { motiaIntrospection } from '../../src/services/mcp/motia-introspection'

/**
* Initialization endpoint for MCP introspection service
Copilot is powered by AI and may make mistakes. Always verify output.
@github-actions
Copy link

E2E Test Results ✅

All tests have completed. Tests passed.

Matrix: 2 OS (Ubuntu, macOS) × 2 Templates (Node.js, Python) = 4 jobs

View detailed test results


This comment is automatically posted by the PR E2E Results workflow.

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.

2 participants