iii icon indicating copy to clipboard operation
iii copied to clipboard

Motia mcp server

Open rohitg00 opened this issue 9 months ago • 3 comments

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.

rohitg00 avatar Oct 15 '25 08:10 rohitg00

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

vercel[bot] avatar Oct 15 '25 08:10 vercel[bot]

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

github-actions[bot] avatar Oct 15 '25 08:10 github-actions[bot]

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.

github-actions[bot] avatar Oct 15 '25 08:10 github-actions[bot]