Skip to content

Latest commit

 

History

History
88 lines (65 loc) · 2.89 KB

File metadata and controls

88 lines (65 loc) · 2.89 KB

Try it with the Inspector

The MCP Inspector is an interactive UI for poking at a server: it lists what the server exposes and lets you call it by hand. It is the fastest way to see whether your server does what you think it does.

It is a Node.js application, so this needs npx on your PATH.

STDIO

Point the Inspector at the command that starts your server — it launches the process itself:

npx @modelcontextprotocol/inspector php server.php

Open the URL it prints. Under Tools, call add with a=1 and b=2; you get 3 back. The form the Inspector built for you — a required integer field for each argument — came from the type hints on the method. So will the schema every other MCP host sees.

Under Resources, read config://calculator/settings to get the array back as JSON.

HTTP

A server behind a web server speaks the HTTP transport instead, so the last lines of server.php change — StdioTransport reads stdin and would just block under php -S:

use Http\Discovery\Psr17Factory;
use Mcp\Server\Session\FileSessionStore;
use Mcp\Server\Transport\StreamableHttpTransport;
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;

$request = (new Psr17Factory())->createServerRequestFromGlobals();

$response = Server::builder()
    ->setServerInfo('Calculator', '1.0.0')
    ->setDiscovery(__DIR__, ['.'], excludeDirs: ['vendor'])
    ->setSession(new FileSessionStore(__DIR__.'/sessions'))
    ->build()
    ->run(new StreamableHttpTransport($request));

(new SapiEmitter())->emit($response);

That needs a PSR-17 implementation and an emitter (composer require nyholm/psr7 laminas/laminas-httphandlerrunner). Start it, then give the Inspector its URL:

php -S localhost:8000 server.php
npx @modelcontextprotocol/inspector http://localhost:8000

curl works too, if you would rather see the wire format:

curl -X POST http://localhost:8000 \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","clientInfo":{"name":"test","version":"1.0.0"},"capabilities":{}}}'

Connect a real host

Hosts that launch local servers take the same command the Inspector did. For Claude Desktop, that is an entry in its configuration file:

{
    "mcpServers": {
        "calculator": {
            "command": "php",
            "args": ["/absolute/path/to/server.php"]
        }
    }
}

Use an absolute path: the host does not run the command from your project directory.

Next

  • Add more of what a server can expose: Servers.
  • Put it on the web instead of stdin/stdout: HTTP transport.
  • Drive a server from PHP instead of a UI: Clients.