Token导航 LogoToken导航TokenDH.com
MCP Php Starter logo
开发工具stdio官方级别未说明来源级核验

MCP Php Starter

MCP Server

@modelcontextprotocol/inspector

一个功能完整的模型上下文协议(MCP)PHP服务器模板,展示所有主要MCP功能并提供生产就绪的代码。

工具数

7

提示词数

0

GitHub Stars

2

资源数

0
PHP代码示例JavaScriptVS Code服务器模板VS Code

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

SamMorrowDrums

提供方

SamMorrowDrums

最后核验

2026/5/17 20:23

运行时

Node.js

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

npx @modelcontextprotocol/inspector php bin/server-stdio.php

详细介绍

MCP PHP入门

![CI](https://github.com/SamMorrowDrums/mcp-php-starter/actions/workflows/ci.yml) ![PHP](https://www.php.net/) ![License: MIT](https://opensource.org/licenses/MIT) ![MCP](https://modelcontextprotocol.io/)

PHP中一个功能完整的模型上下文协议(MCP)服务器模板。此入门程序使用干净的生产就绪代码演示了MCP的所有主要功能。

📚 文档

✨ 特性

类别功能描述
工具hello向某人问好
get_weather获取一个城市的当前天气
long_task使用进度更新模拟长时间运行的任务
load_bonus_tool动态注册新的奖励工具
ask_llm使用采样向连接的LLM提问
confirm_action在继续之前请求用户确认
get_feedback请求用户反馈
资源about://server有关此MCP服务器的信息
doc://example示例文档资源
资源模板greeting://{name}为特定的人提供个性化的问候
item://{id}按ID显示特定项目的数据
提示greet生成问候语
code_review审查代码以寻找潜在的改进

🚀 快速开始

先决条件

安装

# Clone the repository
git clone https://github.com/SamMorrowDrums/mcp-php-starter.git
cd mcp-php-starter

# Install dependencies
composer install

运行服务器

stdio传输 (地方发展):

composer start:stdio
# or
php bin/server-stdio.php

HTTP传输 (用于远程/web部署):

composer start:http
# Server runs on http://localhost:3000

🔧 VS代码集成

该项目包括用于无缝开发的VS代码配置:

  1. 在VS Code中打开项目
  2. MCP配置位于 .vscode/mcp.json
  3. 使用VS Code的MCP工具测试服务器

📁 项目结构

.
├── bin/
│   ├── server-stdio.php   # stdio transport entrypoint
│   └── server-http.php    # HTTP transport entrypoint
├── public/
│   └── index.php          # HTTP web entrypoint
├── src/
│   └── McpElements.php    # Tools, resources, and prompts
├── tests/
│   └── ...
├── .vscode/
│   └── mcp.json           # MCP server configuration
├── composer.json
├── server.json            # MCP discovery configuration
└── README.md

🛠️ 发展

# Install dependencies
composer install

# Run code style check
composer cs-check

# Fix code style
composer cs-fix

# Run tests
composer test

🔍 MCP 检查员

MCP 检查员 是测试和调试MCP服务器的重要开发工具。

运行检查器

npx @modelcontextprotocol/inspector php bin/server-stdio.php

检查员提供什么

  • 工具选项卡:列出并调用所有已注册的带有参数的工具
  • 资源选项卡:浏览和阅读资源
  • 提示选项卡:查看和测试提示模板
  • 日志选项卡:请参阅客户端和服务器之间的JSON-RPC消息

📖 功能示例

具有自定义模式的工具

所有工具都是使用自定义输入模式手动注册的,这些模式包括 titledescription 跨语言一致性字段:

// In ServerFactory.php
->addTool(
    handler: [$elements, 'hello'],
    name: 'hello',
    description: 'Say hello to a person',
    inputSchema: [
        'type' => 'object',
        'properties' => [
            'name' => [
                'type' => 'string',
                'title' => 'Name',
                'description' => 'Name of the person to greet',
            ],
        ],
        'required' => ['name'],
    ]
)

资源

->addResource(
    handler: [$elements, 'getAbout'],
    uri: 'about://server',
    name: 'About',
    description: 'Information about this MCP server',
    mimeType: 'text/plain'
)

资源模板

->addResourceTemplate(
    handler: [$elements, 'getPersonalizedGreeting'],
    uriTemplate: 'greeting://{name}',
    name: 'Personalized Greeting',
    description: 'A personalized greeting for a specific person',
    mimeType: 'text/plain'
)

提示

->addPrompt(
    handler: [$elements, 'greetPrompt'],
    name: 'greet',
    description: 'Generate a greeting message'
)

🔐 环境变量

变量描述默认值
PORTHTTP服务器端口3000

🤝 贡献

欢迎投稿!请确保您的更改与其他语言初学者保持功能对等。

📄 许可证

MIT许可证-请参阅 许可证 了解详情。

目录标签

目录标签

PHP代码示例JavaScriptVS Code服务器模板本地部署PHP开发MCP协议开发工具

支持客户端

VS Code

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Node.js

来源包(packageName,安装包名)

@modelcontextprotocol/inspector

工具数量(toolCount,工具数)

7

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP