Why Integrate Your MCP Server?
Integrating your MCP server with Mindset AI enables powerful AI-driven automation for your organization:- Extend AI Capabilities: Your custom tools and data sources become accessible to AI agents, enabling them to perform domain-specific tasks unique to your business
- Maintain Control: You retain full control over your data and business logic while leveraging Mindset AI’s Agents
- User-Specific Actions: AI agents can perform actions on behalf of specific users in your system, maintaining proper access controls and audit trails
- Seamless Integration: Once registered, your tools appear natively within the Mindset AI platform, requiring no additional integration work
Overview
This guide describes how to implement and register your Model Context Protocol (MCP) server with the Mindset AI platform. Once integrated, your MCP server’s tools can be made available to your AI agents running on our platform.Architecture
The integration is straightforward:- You implement an MCP server that validates API keys and provides tools
- You register your server URL and API key with Mindset AI
- Mindset AI sends requests to your server with the API key and user context
- Your server validates both and processes the requests
Critical Decision: Use an MCP Library
Recommended: Use FastMCP or the Official MCP SDK
We strongly recommend using an established MCP library: Python (Recommended):- FastMCP v2.10+ - Pythonic, production-ready, handles all protocol complexity
- Official MCP Python SDK
Why This Matters: Common Integration Issues
Manual JSON-RPC/MCP implementations can encounter protocol compliance issues:- Tool responses are missing required
result/errorfield - Notification handling is incorrect → Protocol violations
- Missing MCP-specific fields → Incomplete implementation
- Inconsistent error codes → Poor error handling
Manual Implementation Requirements
If you choose to implement without a library (not recommended), you must thoroughly familiarize yourself with both the JSON-RPC 2.0 and MCP specifications, and ensure your server is fully compliant with both standards:- JSON-RPC 2.0 Specification
- Required response fields (
resultXORerror) - Notification handling (requests without
id) - Error codes and structures
- ID type preservation
- Required response fields (
- Model Context Protocol Specification
- Tool discovery (
tools/list) - Tool execution (
tools/call) - Response content structures
- Optional MCP fields (
isError,structuredContent)
- Tool discovery (
- Validation Requirements
- You must pass all tests in the “Testing Your Implementation” section below
- You must handle all edge cases that libraries handle automatically
- You must stay current with spec updates
When Manual Implementation Might Make Sense
Consider manual implementation only if:- You have an existing JSON-RPC infrastructure to integrate with
- You need specific protocol customizations that libraries don’t support
- You have deep JSON-RPC/MCP expertise on your team
Authentication
Authentication uses simple API key validation:- You generate a secure API key for your MCP server (this is a secret you create and control)
- You provide this key to Mindset AI when registering your MCP server
- Mindset AI stores this securely and includes it in the Authorization header as a Bearer token with every request
- Your MCP server validates the API key before processing requests
Important: The API key is generated by you, not by Mindset AI. Use a cryptographically secure random string (e.g., openssl rand -hex 32 or equivalent in your preferred language). You’ll provide this key to Mindset AI during the MCP server registration process.
Registration vs Runtime Authentication
Registration endpoints must only validate API keys Your MCP server will be called in two different contexts:1. Registration Context (No Agent Session)
When customers register your MCP server with Mindset AI, the platform calls these endpoints to validate the server:initialize- Establish connection and capabilitiesnotifications/initialized- Confirm initializationtools/list- Discover available tools
x-session-tagsx-user-id
x-session-tags) for these endpoints. If you do, registration will fail because no session data exists during registration. These endpoints should only validate the API key in the Authorization header.
2. Runtime Context (if the AgentSessions API is used to create Agent sessions)
When agents call your tools during conversations, the platform calls:tools/call- Execute a specific tool
x-session-tagswill contain session-specific tagsx-user-idwill identify the current userx-app-uidwill identify the application
x-session-tags, etc.) for tools/call requests.
User Context and Permissions
Mindset AI includes the following lowercase headers in every request:Headers Provided by Mindset AI
- x-user-id: Identifies the end user on whose behalf the action is being taken
- x-app-uid: The application identifier
- x-session-tags: Contains the exact JSON array of tags provided when creating the agent session via the AgentSessions API. These are arbitrary strings that you define for your own filtering/segmentation needs (e.g., [“department:sales”, “SALES”, “region:north”, “Q4-2024”, “premium_access”]). If you don’t need filtering, you can provide an empty array or omit tags when creating the session.
- x-human-uid: Internal Mindset AI identifier for the user (optional, for informational/logging purposes only)
Important Distinction: Current User vs. Target Users
The x-user-id header identifies the CURRENT user - the person making the request. However, your tools may need to operate on OTHER users:- Regular tools: Act on behalf of the current user (e.g., “get my settings”, “update my profile”)
- Use x-user-id header to identify who is making the request
- Never accept user_id as a parameter for these operations
- Admin tools: Allow the current user to manage other users (e.g., “create user John”, “add user Alice to group”)
- Use x-user-id header to identify the ADMIN performing the action
- Accept user_id/email as parameters to identify the TARGET users being managed
- Verify the current user has admin permissions before allowing these operations
- Validate the user ID against your user database
- For admin tools, verify the x-user-id has appropriate permissions
- Use x-session-tags for additional filtering or access control
- Map to your internal user ID for operations
- Apply user-specific permissions and access controls
- Log actions for audit purposes
Implementation Requirements
Your MCP server should:- Implement JSON-RPC 2.0 and MCP protocols: Your server must be fully compliant with the JSON-RPC 2.0 specification and Model Context Protocol specification. We recommend using FastMCP or an official MCP SDK, which handle all protocol requirements automatically.
- Validate API Keys: Check the Bearer token in the Authorization header against your configured API key
- Enforce User Permissions: Use the
x-user-idheader to identify users and apply appropriate access controls - Return Proper Responses: Follow JSON-RPC 2.0 response structure (every response must have either
resultorerrorfield) - Follow Tool Naming Convention: Tool names must match the pattern
^[a-zA-Z0-9_-]+(only letters, numbers, underscores, and hyphens). Tool names with dots, spaces, or special characters will cause errors with OpenAI and other LLM providers. For example, usesearch_for_userinstead ofsearch.for.user.
- Validate Bearer tokens (API keys)
- Implement HTTP endpoints according to the JSON-RPC 2.0 and MCP specifications
- Parse the
x-user-idand optionally thex-human-uidheaders from requests - Return JSON-RPC 2.0 compliant responses
Example Python Implementation with FastMCP
FastMCP is the recommended framework for building MCP servers in Python. It dramatically simplifies development by handling all the protocol complexities while providing production-ready features like authentication, middleware support, and deployment tools. Learn more at gofastmcp.com.1. Setting Up API Key Configuration
2. Minimal Authentication Middleware
3. Initialize MCP Server with Middleware
4. Implement Your Tools
Tool Docstrings And Logical Variable Names Are Critical
The docstring is what the LLM uses to decide when to call your tool. Keep it concise but descriptive - explain WHAT the tool does and WHEN it should be used. Tool Description Length: Tool descriptions should be at least 5 words. Descriptions shorter than 5 words may not provide enough context for LLMs to understand when and how to use the tool effectively. For example, “Search for users” (3 words) is too short, but “Search for users by name or email” (7 words) provides clear context. Parameter names should be self-explanatory - the LLM uses these names to understand what data to provide. For example, usesearch_query not q, include_completed not inc_comp. Clear names reduce errors and improve the LLM’s ability to call your tool correctly.
Always use type hints for parameters as FastMCP uses these to validate inputs.
Return Object Guidelines
Always include a status field - Use “success”, “error”, or “partial” to help the LLM understand the outcome.
Use message for human-readable outcomes - Brief, actionable information the LLM can relay to the user. Avoid including IDs or technical identifiers in messages.
Use data for structured results - Machine-readable data the LLM needs to process further. This is where identifiers should live when needed.
Include error details in the data field for errors - When returning an error status, include API/system error details in the data field so the agent has feedback and can adapt subsequent attempts. For example, include rate limit information, validation errors, or specific fields that failed.
Be cautious with internal identifiers - Avoid exposing internal database keys or system internals that could confuse users or create security risks. However, you may need to include public-facing identifiers (like course IDs, document IDs, or order numbers) in the data field when they’re necessary for subsequent operations or user reference. Keep IDs out of the message field - use natural language there instead.
Important: Tool Return Value vs Wire Format
If using FastMCP/SDK: Your tool functions return plain data structures (objects/dictionaries). The library automatically wraps these in the MCP-requiredcontent field before sending on the wire. You don’t need to handle this wrapping yourself.
If implementing manually: You must wrap your response in the MCP content structure yourself. The examples below show what your tool function returns when using an MCP library. For manual implementations, see the “Expected Response” section in “Testing Your Implementation” for the complete wire format with the content field.
5. Run the Server
Testing Your Implementation
These tests verify JSON-RPC 2.0 and MCP protocol compliance. All servers (library-based or manual) must pass these tests before registration with Mindset.- If using FastMCP/SDK: These tests verify your tool logic works correctly (protocol compliance is handled automatically)
- If implementing manually: These tests are essential - they catch protocol violations that break agent integration
The MCP Handshake Test Sequence
When connecting, the Mindset agent performs this exact sequence:- Initialize - Establish connection and exchange capabilities
- Notification - Confirm initialization complete (no response expected)
- List Tools - Get available tools
- Call Tool - Execute a tool
1. Test Tool Discovery
2. Test Tool Execution
{"status":"success","message":"...","data":{...}} and FastMCP automatically wraps it in the MCP-required content field. Manual implementations must handle this wrapping explicitly.
3. Test Security Failures
4. Minimal Python Test Script
Production Considerations
Deployment
Your MCP server requires HTTPS in production. Deploy using your preferred infrastructure - containerization, serverless platforms, or traditional hosting all work well with the MCP protocol.Security
- For regular user operations: Don’t accept user identification in tool parameters - rely exclusively on the x-user-id header to identify the current user
- For admin operations: The x-user-id identifies the admin, while target users must be specified as parameters (after verifying admin permissions)
- Consider integrating with your existing user database and RBAC systems
- Rate limiting can help prevent abuse
- Use your organization’s standard secret management practices
- Plan for API key rotation policies
Operations
- Implement logging and monitoring appropriate for your environment
- Consider deploying behind load balancers with health checks
- Set up alerts for repeated authentication failures