1. Go to this page and download the library: Download he426100/mcp-sdk-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
he426100 / mcp-sdk-php example snippets
// 一个带有测试用 prompts 列表的基本示例服务器
pt;
use Mcp\Types\PromptArgument;
use Mcp\Types\PromptMessage;
use Mcp\Types\ListPromptsResult;
use Mcp\Types\TextContent;
use Mcp\Types\Role;
use Mcp\Types\GetPromptResult;
use Mcp\Types\GetPromptRequestParams;
// 创建服务器实例
$server = new Server('example-server');
// 注册 prompt 处理器
$server->registerHandler('prompts/list', function($params) {
$prompt = new Prompt(
name: 'example-prompt',
description: 'An example prompt template',
arguments: [
new PromptArgument(
name: 'arg1',
description: 'Example argument',
red: true
)
]
);
return new GetPromptResult(
messages: [
new PromptMessage(
role: Role::USER,
content: new TextContent(
text: "Example prompt text with argument: $argValue"
)
)
],
description: 'Example prompt'
);
});
// 创建初始化选项并运行服务器
$initOptions = $server->createInitializationOptions();
$runner = new ServerRunner();
$runner->run($server, $initOptions);
cp\Server\Server;
use Mcp\Server\ServerRunner;
use Mcp\Annotation\Prompt;
use Mcp\Tool\McpHandlerRegistrar;
$server = new Server('example-server');
// 使用注解定义处理 prompt 的类
class ExamplePrompts
{
#[Prompt(
name: 'example-prompt',
description: 'An example prompt template',
arguments: [
'arg1' => [
'description' => 'Example argument',
'
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.