---
title: "Reference: Mastra.getMCPServer() | Core"
description: "Documentation for the `Mastra.getMCPServer()` method in Mastra, which retrieves a specific MCP server instance by ID and optional version."
packages:
  - "@mastra/core"
---

# Mastra.getMCPServer()

The `.getMCPServer()` method retrieves an MCP server instance by its registry key (the key used when registering the server in the `mcpServers` configuration). For retrieving by the server's intrinsic `id` property, use `.getMCPServerById()` instead.

## Usage example

```typescript
// Register an MCP server with a registry key
const myServer = new MCPServer({
  id: 'my-mcp-server',
  name: 'My Server',
  version: '1.0.0',
  tools: { /* ... */ },
});

export const mastra = new Mastra({
  mcpServers: {
    customKey: myServer,  // 'customKey' is the registry key
  },
});

// Retrieve by registry key
const server = mastra.getMCPServer('customKey');

// Alternatively, retrieve by intrinsic ID
const serverById = mastra.getMCPServerById('my-mcp-server');
```

## Parameters

<PropertiesTable
  content={[
    {
      name: "registryKey",
      type: "string",
      description:
        "The registry key used when registering the MCP server in the mcpServers configuration object. This is the key in the key-value pair, not the server's intrinsic id property.",
    },
  ]}
/>

## Returns

<PropertiesTable
  content={[
    {
      name: "server",
      type: "MCPServerBase | undefined",
      description:
        "The MCP server instance with the specified registry key, or undefined if not found.",
    },
  ]}
/>

## Related Methods

- [Mastra.getMCPServerById()](/reference/v1/core/getMCPServerById) - Retrieve an MCP server by its intrinsic `id` property
- [Mastra.listMCPServers()](/reference/v1/core/listMCPServers) - List all registered MCP servers

## See Also

- [MCP overview](/docs/v1/mcp/overview)
- [MCP server reference](/reference/v1/tools/mcp-server)
