NAME

Claude::Agent::MCP::Server - SDK MCP server configuration

SYNOPSIS

use Claude::Agent qw(tool create_sdk_mcp_server);

my $calc = tool(
    'calculate',
    'Perform basic arithmetic',
    {
        type       => 'object',
        properties => {
            a         => { type => 'number' },
            b         => { type => 'number' },
            operation => { type => 'string', enum => ['add', 'subtract', 'multiply', 'divide'] },
        },
        required => ['a', 'b', 'operation'],
    },
    sub {
        my ($args) = @_;
        my ($a, $b, $op) = @{$args}{qw(a b operation)};
        my $result = $op eq 'add'      ? $a + $b
                   : $op eq 'subtract' ? $a - $b
                   : $op eq 'multiply' ? $a * $b
                   : $op eq 'divide'   ? ($b != 0 ? $a / $b : 'Error: division by zero')
                   :                     'Error: unknown operation';
        return { content => [{ type => 'text', text => "Result: $result" }] };
    }
);

my $server = create_sdk_mcp_server(
    name    => 'math',
    tools   => [$calc],
    version => '1.0.0',
);

# Tools are named: mcp__math__calculate

DESCRIPTION

Defines an SDK MCP server that runs tool handlers locally in your Perl process.

When you pass an SDK server to mcp_servers in the options, the SDK:

1. Creates a Unix socket to communicate with child processes 2. Spawns a lightweight MCP server process (SDKRunner) 3. Passes the runner to the CLI as a stdio MCP server 4. When the CLI calls a tool, the runner forwards it via the socket 5. Your handler executes and the result flows back

This allows your tools to access your application's state, databases, and APIs while being fully integrated with Claude's tool system.

ATTRIBUTES

  • name - Server name (used in tool naming: mcp__<name>__<tool>)

  • tools - ArrayRef of Claude::Agent::MCP::ToolDefinition objects

  • version - Server version (default: '1.0.0')

  • type - Always 'sdk' for SDK servers

METHODS

to_hash

my $hash = $server->to_hash();

Convert the server configuration to a hash for JSON serialization.

get_tool

my $tool = $server->get_tool($tool_name);

Get a tool definition by name.

tool_names

my $names = $server->tool_names();

Get the full MCP tool names for all tools in this server.

AUTHOR

LNATION, <email at lnation.org>

LICENSE

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under The Artistic License 2.0 (GPL Compatible).