Skip to content

Commit 9946beb

Browse files
refactor: consolidate HTTP example to use shared dependencies
1 parent 28388c9 commit 9946beb

File tree

6 files changed

+17
-122
lines changed

6 files changed

+17
-122
lines changed

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
"phpunit/phpunit": "^10.5",
3838
"psr/cache": "^3.0",
3939
"symfony/console": "^6.4 || ^7.3",
40-
"symfony/process": "^6.4 || ^7.3"
40+
"symfony/process": "^6.4 || ^7.3",
41+
"nyholm/psr7": "^1.8",
42+
"nyholm/psr7-server": "^1.1",
43+
"laminas/laminas-httphandlerrunner": "^2.12"
4144
},
4245
"autoload": {
4346
"psr-4": {
@@ -54,10 +57,11 @@
5457
"Mcp\\Example\\DependenciesStdioExample\\": "examples/06-custom-dependencies-stdio/",
5558
"Mcp\\Example\\ComplexSchemaHttpExample\\": "examples/07-complex-tool-schema-http/",
5659
"Mcp\\Example\\SchemaShowcaseExample\\": "examples/08-schema-showcase-streamable/",
60+
"Mcp\\Example\\HttpTransportExample\\": "examples/10-simple-http-transport/",
5761
"Mcp\\Tests\\": "tests/"
5862
}
5963
},
6064
"config": {
6165
"sort-packages": true
6266
}
63-
}
67+
}

examples/10-simple-http-transport/.gitignore

Lines changed: 0 additions & 55 deletions
This file was deleted.

examples/10-simple-http-transport/src/McpElements.php renamed to examples/10-simple-http-transport/McpElements.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace App;
3+
namespace Mcp\Example\HttpTransportExample;
44

55
use Mcp\Capability\Attribute\McpPrompt;
66
use Mcp\Capability\Attribute\McpResource;

examples/10-simple-http-transport/README.md

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,23 @@
22

33
This example demonstrates how to use the MCP SDK with HTTP transport using the StreamableHttpTransport. It provides a complete HTTP-based MCP server that can handle JSON-RPC requests over HTTP POST.
44

5-
## Installation
6-
7-
```bash
8-
cd /path/to/your/project/examples/10-simple-http-transport
9-
composer update
10-
```
11-
125
## Usage
136

14-
### As HTTP Server
15-
16-
You can use this with any HTTP server or framework that can proxy requests to PHP:
7+
**Step 1: Start the HTTP server**
178

189
```bash
19-
# Using PHP built-in server (for testing)
20-
php -S localhost:8000
21-
22-
# Or with Apache/Nginx, point your web server to serve this directory
10+
cd examples/10-simple-http-transport
11+
php -S localhost:8000 server.php
2312
```
2413

25-
### With MCP Inspector
26-
27-
Run with the MCP Inspector for testing:
14+
**Step 2: Connect with MCP Inspector**
2815

2916
```bash
3017
npx @modelcontextprotocol/inspector http://localhost:8000
3118
```
3219

33-
## API
34-
35-
The server accepts JSON-RPC 2.0 requests via HTTP POST.
36-
37-
### Available Endpoints
20+
## Available Features
3821

3922
- **Tools**: `current_time`, `calculate`
4023
- **Resources**: `info://server/status`, `config://app/settings`
4124
- **Prompts**: `greet`
42-
43-
### Example Request
44-
45-
```bash
46-
curl -X POST http://localhost:8000 \
47-
-H "Content-Type: application/json" \
48-
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "current_time"}}'
49-
```

examples/10-simple-http-transport/composer.json

Lines changed: 0 additions & 31 deletions
This file was deleted.

examples/10-simple-http-transport/index.php renamed to examples/10-simple-http-transport/server.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

3-
require_once __DIR__ . '/vendor/autoload.php';
3+
require_once dirname(__DIR__) . '/bootstrap.php';
4+
chdir(__DIR__);
45

56
use Mcp\Server;
67
use Mcp\Server\Transport\StreamableHttpTransport;
@@ -14,8 +15,9 @@
1415
$request = $creator->fromGlobals();
1516

1617
$server = Server::make()
17-
->withServerInfo('HTTP MCP Server', '1.0.0')
18-
->withDiscovery(__DIR__, ['src'])
18+
->withServerInfo('HTTP MCP Server', '1.0.0', 'MCP Server over HTTP transport')
19+
->withContainer(container())
20+
->withDiscovery(__DIR__, ['.'])
1921
->build();
2022

2123
$transport = new StreamableHttpTransport($request, $psr17Factory, $psr17Factory);

0 commit comments

Comments
 (0)