NAME

Claude::Agent::MCP::Server - An MCP server that runs inside your process

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',
);

DESCRIPTION

A set of Claude::Agent::MCP::ToolDefinition objects served to the CLI over the SDK control channel: the CLI sends each MCP request as a mcp_message control request and Claude::Agent::MCP::SDKBridge answers it in this process. Nothing is spawned. The tools are named mcp__<name>__<tool>; list them in allowed_tools or they will prompt for permission.

ATTRIBUTES

name

The server's name. Required.

tools

ArrayRef of Claude::Agent::MCP::ToolDefinition.

version

Reported to the CLI in the MCP handshake. Default 1.0.0.

type

Always sdk. Read only.

METHODS

new

Takes a flat list of name/value pairs. Unknown names are ignored.

to_hash

my $hash = $server->to_hash;

{ type, name, version, tools } with each tool's to_hash.

to_cli_config

my $config = $server->to_cli_config;

{ type => 'sdk', name => $name }: the entry written to --mcp-config, which tells the CLI to route the server's requests back over the control channel.

get_tool

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

The tool with that (unprefixed) name, or undef.

tool_names

my $names = $server->tool_names;

ArrayRef of the full mcp__server__tool names.

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).