|
| 1 | + |
| 2 | +> 注:当前项目为 Serverless Devs 应用,由于应用中会存在需要初始化才可运行的变量(例如应用部署地区、函数名等等),所以**不推荐**直接 Clone 本仓库到本地进行部署或直接复制 s.yaml 使用,**强烈推荐**通过 `s init ${模版名称}` 的方法或应用中心进行初始化,详情可参考[部署 & 体验](#部署--体验) 。 |
| 3 | +
|
| 4 | +# start-mcp-json 帮助文档 |
| 5 | + |
| 6 | +<description> |
| 7 | + |
| 8 | +JSON MCP Server |
| 9 | + |
| 10 | +</description> |
| 11 | + |
| 12 | + |
| 13 | +## 资源准备 |
| 14 | + |
| 15 | +使用该项目,您需要有开通以下服务并拥有对应权限: |
| 16 | + |
| 17 | +<service> |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +| 服务/业务 | 权限 | 相关文档 | |
| 22 | +| --- | --- | --- | |
| 23 | +| 函数计算 | AliyunFCFullAccess | [帮助文档](https://help.aliyun.com/product/2508973.html) [计费文档](https://help.aliyun.com/document_detail/2512928.html) | |
| 24 | + |
| 25 | +</service> |
| 26 | + |
| 27 | +<remark> |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +</remark> |
| 32 | + |
| 33 | +<disclaimers> |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +</disclaimers> |
| 38 | + |
| 39 | +## 部署 & 体验 |
| 40 | + |
| 41 | +<appcenter> |
| 42 | + |
| 43 | +- :fire: 通过 [云原生应用开发平台 CAP](https://cap.console.aliyun.com/template-detail?template=start-mcp-json) ,[](https://cap.console.aliyun.com/template-detail?template=start-mcp-json) 该应用。 |
| 44 | + |
| 45 | +</appcenter> |
| 46 | +<deploy> |
| 47 | + |
| 48 | + |
| 49 | +</deploy> |
| 50 | + |
| 51 | +## 案例介绍 |
| 52 | + |
| 53 | +<appdetail id="flushContent"> |
| 54 | + |
| 55 | +# JSON MCP Server (@gongrzhe/server-json-mcp@1.0.3) |
| 56 | + |
| 57 | +A JSON Model Context Protocol (MCP) server implementation for querying and manipulating JSON data. This server enables LLMs to interact with JSON data through a set of standardized tools. |
| 58 | + |
| 59 | + |
| 60 | +## Installation & Usage |
| 61 | + |
| 62 | +```bash |
| 63 | +# Using npx with specific version (recommended) |
| 64 | +npx @gongrzhe/server-json-mcp@1.0.3 |
| 65 | + |
| 66 | +# Install specific version globally |
| 67 | +npm install -g @gongrzhe/server-json-mcp@1.0.3 |
| 68 | + |
| 69 | +# Run after global installation |
| 70 | +server-json-mcp |
| 71 | +``` |
| 72 | + |
| 73 | +## Components |
| 74 | + |
| 75 | +### Tools |
| 76 | + |
| 77 | +- **query** |
| 78 | + - Query JSON data using JSONPath syntax with extended operations |
| 79 | + - Input: |
| 80 | + - `url` (string): URL of the JSON data source |
| 81 | + - `jsonPath` (string): JSONPath expression with optional operations |
| 82 | + |
| 83 | +- **filter** |
| 84 | + - Filter JSON data using conditions |
| 85 | + - Input: |
| 86 | + - `url` (string): URL of the JSON data source |
| 87 | + - `jsonPath` (string): Base JSONPath expression |
| 88 | + - `condition` (string): Filter condition |
| 89 | + |
| 90 | +### Supported Operations |
| 91 | + |
| 92 | +#### Array Operations |
| 93 | +- **Slicing**: `$[0:5]`, `$[-3:]`, `$[1:4]` |
| 94 | +- **Sorting**: `$.sort(price)`, `$.sort(-price)` |
| 95 | +- **Distinct**: `$.distinct()` |
| 96 | +- **Transformations**: |
| 97 | + - Map: `$.map(fieldName)` |
| 98 | + - Flatten: `$.flatten()` |
| 99 | + - Union: `$.union([1,2,3])` |
| 100 | + - Intersection: `$.intersection([1,2,3])` |
| 101 | + |
| 102 | +#### String Operations |
| 103 | +- **Case**: `$.toLowerCase()`, `$.toUpperCase()` |
| 104 | +- **Tests**: `$.startsWith('test')`, `$.endsWith('test')` |
| 105 | +- **Search**: `$.contains('test')`, `$.matches('pattern')` |
| 106 | + |
| 107 | +#### Numeric Operations |
| 108 | +- **Math**: `$.math(+10)`, `$.pow2()` |
| 109 | +- **Rounding**: `$.round()`, `$.floor()`, `$.ceil()` |
| 110 | +- **Functions**: `$.abs()`, `$.sqrt()` |
| 111 | + |
| 112 | +#### Date Operations |
| 113 | +- **Format**: `$.format('YYYY-MM-DD')` |
| 114 | +- **Check**: `$.isToday()` |
| 115 | +- **Modify**: `$.add(1, 'days')` |
| 116 | + |
| 117 | +#### Aggregation Operations |
| 118 | +- **Group**: `$.groupBy(category)` |
| 119 | +- **Stats**: `$.sum(price)`, `$.avg(price)`, `$.min(price)`, `$.max(price)` |
| 120 | + |
| 121 | +## Configuration |
| 122 | + |
| 123 | +### Usage with Claude Desktop |
| 124 | + |
| 125 | +To use this server with the Claude Desktop app, add the following configuration to your `claude_desktop_config.json`: |
| 126 | + |
| 127 | +```json |
| 128 | +{ |
| 129 | + "json": { |
| 130 | + "command": "npx", |
| 131 | + "args": [ |
| 132 | + "@gongrzhe/server-json-mcp@1.0.3" |
| 133 | + ] |
| 134 | + } |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +Alternatively, you can use the node command directly if you have the package installed: |
| 139 | + |
| 140 | +```json |
| 141 | +{ |
| 142 | + "json": { |
| 143 | + "command": "node", |
| 144 | + "args": [ |
| 145 | + "path/to/build/index.js" |
| 146 | + ] |
| 147 | + } |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +## Development |
| 152 | + |
| 153 | +### Building from Source |
| 154 | + |
| 155 | +1. Clone the repository |
| 156 | +2. Install dependencies: |
| 157 | + ```bash |
| 158 | + npm install |
| 159 | + ``` |
| 160 | +3. Build the project: |
| 161 | + ```bash |
| 162 | + npm run build |
| 163 | + ``` |
| 164 | + |
| 165 | +## Notes |
| 166 | + |
| 167 | +1. All JSONPath expressions start with `$` representing the root object |
| 168 | +2. Array indices are zero-based |
| 169 | +3. String values in operations should be wrapped in quotes |
| 170 | +4. Date operations support 'days', 'months', and 'years' units |
| 171 | +5. Numeric operations support basic arithmetic operators (+, -, *, /) |
| 172 | + |
| 173 | +## License |
| 174 | + |
| 175 | +MIT |
| 176 | + |
| 177 | +</appdetail> |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | +## 使用流程 |
| 186 | + |
| 187 | +<usedetail id="flushContent"> |
| 188 | + |
| 189 | +部署完成拿到 URL 后,准备好支持 SSE 的 MCP Client,通过 SSETransport 进行连接。 |
| 190 | + |
| 191 | +</usedetail> |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | + |
0 commit comments