mapbox-create-map-mcp 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -1
- package/package.json +1 -1
- package/src/server.js +49 -22
package/README.md
CHANGED
|
@@ -8,7 +8,42 @@
|
|
|
8
8
|
npm install mapbox-create-map-mcp
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## MCP 服务使用
|
|
12
|
+
|
|
13
|
+
### 直接启动
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx mapbox-create-map-mcp
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### MCP 客户端配置
|
|
20
|
+
|
|
21
|
+
在 MCP 客户端(如 Claude Desktop、Cursor 等)的配置文件中添加:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"mcpServers": {
|
|
26
|
+
"mapbox-createmap": {
|
|
27
|
+
"command": "npx",
|
|
28
|
+
"args": ["mapbox-create-map-mcp"]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### MCP 工具
|
|
35
|
+
|
|
36
|
+
**CreateMap** - 根据配置生成地图图层配置信息
|
|
37
|
+
|
|
38
|
+
输入参数:
|
|
39
|
+
- `title` (string, 必需): 地图标题
|
|
40
|
+
- `description` (string, 必需): 地图描述
|
|
41
|
+
- `layers` (array, 必需): 图层配置数组
|
|
42
|
+
- `baseStyle` (string, 可选): 底图样式
|
|
43
|
+
- `center` (array, 可选): 中心点 [经度, 纬度]
|
|
44
|
+
- `zoom` (number, 可选): 缩放级别
|
|
45
|
+
|
|
46
|
+
## JavaScript 库使用
|
|
12
47
|
|
|
13
48
|
### 基本使用
|
|
14
49
|
|
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -62,6 +62,12 @@ class McpServer {
|
|
|
62
62
|
async handleRequest(request) {
|
|
63
63
|
const { id, method, params } = request;
|
|
64
64
|
|
|
65
|
+
// 通知类型的消息不需要返回响应
|
|
66
|
+
if (method && method.startsWith('notifications/')) {
|
|
67
|
+
// 处理通知,不返回任何内容
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
try {
|
|
66
72
|
let result;
|
|
67
73
|
|
|
@@ -82,6 +88,10 @@ class McpServer {
|
|
|
82
88
|
result = this.handleResourcesList();
|
|
83
89
|
break;
|
|
84
90
|
|
|
91
|
+
case 'ping':
|
|
92
|
+
result = {};
|
|
93
|
+
break;
|
|
94
|
+
|
|
85
95
|
default:
|
|
86
96
|
this.sendError(-32601, `Method not found: ${method}`, id);
|
|
87
97
|
return;
|
|
@@ -114,11 +124,44 @@ class McpServer {
|
|
|
114
124
|
const metadata = this.createMap.metadata;
|
|
115
125
|
const layerMetadata = this.createMap.layerMetadata;
|
|
116
126
|
|
|
127
|
+
// 合并所有图层类型的配置属性
|
|
128
|
+
const allConfigProperties = {};
|
|
129
|
+
|
|
130
|
+
// point 属性
|
|
131
|
+
for (const key in layerMetadata.point) {
|
|
132
|
+
const prop = layerMetadata.point[key];
|
|
133
|
+
allConfigProperties[key] = {
|
|
134
|
+
type: prop.type,
|
|
135
|
+
description: `[point图层] ${prop.description}`
|
|
136
|
+
};
|
|
137
|
+
if (prop.default !== undefined) allConfigProperties[key].default = prop.default;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// linestring 属性
|
|
141
|
+
for (const key in layerMetadata.linestring) {
|
|
142
|
+
const prop = layerMetadata.linestring[key];
|
|
143
|
+
allConfigProperties[key] = {
|
|
144
|
+
type: prop.type,
|
|
145
|
+
description: `[linestring图层] ${prop.description}`
|
|
146
|
+
};
|
|
147
|
+
if (prop.default !== undefined) allConfigProperties[key].default = prop.default;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// polygon 属性
|
|
151
|
+
for (const key in layerMetadata.polygon) {
|
|
152
|
+
const prop = layerMetadata.polygon[key];
|
|
153
|
+
allConfigProperties[key] = {
|
|
154
|
+
type: prop.type,
|
|
155
|
+
description: `[polygon图层] ${prop.description}`
|
|
156
|
+
};
|
|
157
|
+
if (prop.default !== undefined) allConfigProperties[key].default = prop.default;
|
|
158
|
+
}
|
|
159
|
+
|
|
117
160
|
return {
|
|
118
161
|
tools: [
|
|
119
162
|
{
|
|
120
163
|
name: 'CreateMap',
|
|
121
|
-
description: '根据配置生成地图图层配置信息,返回FeatureCollection
|
|
164
|
+
description: '根据配置生成地图图层配置信息,返回FeatureCollection格式的结果用于渲染。图层类型支持point(点)、linestring(线)、polygon(面)三种。',
|
|
122
165
|
inputSchema: {
|
|
123
166
|
type: 'object',
|
|
124
167
|
properties: {
|
|
@@ -133,23 +176,20 @@ class McpServer {
|
|
|
133
176
|
baseStyle: {
|
|
134
177
|
type: 'string',
|
|
135
178
|
enum: metadata.baseStyle.enum,
|
|
136
|
-
default: metadata.baseStyle.default,
|
|
137
179
|
description: metadata.baseStyle.description
|
|
138
180
|
},
|
|
139
181
|
center: {
|
|
140
182
|
type: 'array',
|
|
141
183
|
items: { type: 'number' },
|
|
142
|
-
default: metadata.center.default,
|
|
143
184
|
description: metadata.center.description
|
|
144
185
|
},
|
|
145
186
|
zoom: {
|
|
146
187
|
type: 'number',
|
|
147
|
-
default: metadata.zoom.default,
|
|
148
188
|
description: metadata.zoom.description
|
|
149
189
|
},
|
|
150
190
|
layers: {
|
|
151
191
|
type: 'array',
|
|
152
|
-
description:
|
|
192
|
+
description: '图层配置数组。每个图层需要id和type,type决定了config中可用的属性:point类型用circle-*属性,lingestring类型用line-*属性,polygon类型用fill-*属性',
|
|
153
193
|
items: {
|
|
154
194
|
type: 'object',
|
|
155
195
|
properties: {
|
|
@@ -157,27 +197,14 @@ class McpServer {
|
|
|
157
197
|
type: {
|
|
158
198
|
type: 'string',
|
|
159
199
|
enum: ['point', 'linestring', 'polygon'],
|
|
160
|
-
description: '
|
|
200
|
+
description: '图层类型: point(点,使用circle-*属性), linestring(线,使用line-*属性), polygon(面,使用fill-*属性)'
|
|
161
201
|
},
|
|
162
202
|
data: { type: 'object', description: 'GeoJSON格式的地理数据' },
|
|
163
|
-
fileUrl: { type: 'string', description: '
|
|
203
|
+
fileUrl: { type: 'string', description: '数据URL地址' },
|
|
164
204
|
config: {
|
|
165
205
|
type: 'object',
|
|
166
|
-
description: '
|
|
167
|
-
|
|
168
|
-
point: {
|
|
169
|
-
description: '当type="point"时,config使用以下属性(对应Mapbox circle图层)',
|
|
170
|
-
properties: this.formatProperties(layerMetadata.point)
|
|
171
|
-
},
|
|
172
|
-
linestring: {
|
|
173
|
-
description: '当type="linestring"时,config使用以下属性(对应Mapbox line图层)',
|
|
174
|
-
properties: this.formatProperties(layerMetadata.linestring)
|
|
175
|
-
},
|
|
176
|
-
polygon: {
|
|
177
|
-
description: '当type="polygon"时,config使用以下属性(对应Mapbox fill图层)',
|
|
178
|
-
properties: this.formatProperties(layerMetadata.polygon)
|
|
179
|
-
}
|
|
180
|
-
}
|
|
206
|
+
description: '图层样式配置,根据type选择对应属性: point用circle-*、linestring用line-*、polygon用fill-*',
|
|
207
|
+
properties: allConfigProperties
|
|
181
208
|
}
|
|
182
209
|
},
|
|
183
210
|
required: ['id', 'type']
|