@kkingsbe/carto-art-mcp 1.0.0

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.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
+ import { z } from "zod";
6
+ import fetch from "node-fetch";
7
+ const API_URL = process.env.CARTO_ART_API_URL || "http://localhost:3000/api/v1/posters/generate";
8
+ const server = new Server({
9
+ name: "carto-art-mcp",
10
+ version: "1.0.0",
11
+ }, {
12
+ capabilities: {
13
+ tools: {},
14
+ },
15
+ });
16
+ const GeneratePosterArgumentsSchema = z.object({
17
+ location: z.string().describe("The location to center the map on (e.g., 'Paris, France')"),
18
+ style: z.string().optional().describe("The style ID (e.g., 'blueprint', 'retro', 'minimal')"),
19
+ zoom: z.number().optional().describe("The zoom level (1-20)"),
20
+ pitch: z.number().optional().describe("The pitch of the camera (0-60)"),
21
+ bearing: z.number().optional().describe("The bearing of the camera (0-360)"),
22
+ buildings_3d: z.boolean().optional().describe("Whether to enable 3D buildings"),
23
+ });
24
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
25
+ return {
26
+ tools: [
27
+ {
28
+ name: "generate_poster",
29
+ description: "Generate a beautiful map poster for a given location and style.",
30
+ inputSchema: {
31
+ type: "object",
32
+ properties: {
33
+ location: { type: "string", description: "The location (e.g., 'Paris, France')" },
34
+ style: { type: "string", description: "The style ID (e.g., 'blueprint', 'retro', 'minimal')" },
35
+ zoom: { type: "number", description: "The zoom level (1-20)" },
36
+ pitch: { type: "number", description: "The pitch of the camera (0-60)" },
37
+ bearing: { type: "number", description: "The bearing of the camera (0-360)" },
38
+ buildings_3d: { type: "boolean", description: "Whether to enable 3D buildings" },
39
+ },
40
+ required: ["location"],
41
+ },
42
+ },
43
+ ],
44
+ };
45
+ });
46
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
47
+ if (request.params.name === "generate_poster") {
48
+ const args = GeneratePosterArgumentsSchema.parse(request.params.arguments);
49
+ try {
50
+ // 1. Geocode the location string
51
+ console.error(`Geocoding: ${args.location}`);
52
+ const geocodeBaseUrl = API_URL.replace("/posters/generate", "/geocode");
53
+ const geocodeResponse = await fetch(`${geocodeBaseUrl}?q=${encodeURIComponent(args.location)}&limit=1`, {
54
+ headers: { "Authorization": `Bearer ${process.env.CARTO_ART_API_KEY || "local-dev"}` }
55
+ });
56
+ if (!geocodeResponse.ok) {
57
+ throw new Error(`Geocoding failed: ${geocodeResponse.statusText}`);
58
+ }
59
+ const geocodeData = await geocodeResponse.json();
60
+ if (!geocodeData || geocodeData.length === 0) {
61
+ return {
62
+ content: [{ type: "text", text: `Could not find location: ${args.location}` }],
63
+ isError: true,
64
+ };
65
+ }
66
+ const { lat, lon } = geocodeData[0];
67
+ // 2. Prepare the payload for the new SimplifiedPosterSchema
68
+ const payload = {
69
+ location: {
70
+ lat: parseFloat(lat),
71
+ lng: parseFloat(lon)
72
+ },
73
+ style: args.style || "minimal",
74
+ camera: {
75
+ pitch: args.pitch || 0,
76
+ bearing: args.bearing || 0,
77
+ zoom: args.zoom || 12,
78
+ },
79
+ options: {
80
+ buildings_3d: args.buildings_3d || false,
81
+ high_res: true,
82
+ }
83
+ };
84
+ console.error("Calling generation API with payload:", JSON.stringify(payload));
85
+ // 3. Call the generation API with Accept: image/png
86
+ const imageResponse = await fetch(API_URL, {
87
+ method: "POST",
88
+ headers: {
89
+ "Content-Type": "application/json",
90
+ "Accept": "image/png",
91
+ "Authorization": `Bearer ${process.env.CARTO_ART_API_KEY || "local-dev"}`
92
+ },
93
+ body: JSON.stringify(payload),
94
+ });
95
+ if (!imageResponse.ok) {
96
+ const errorText = await imageResponse.text();
97
+ return {
98
+ content: [{ type: "text", text: `Error from API: ${imageResponse.status} ${imageResponse.statusText}\n${errorText}` }],
99
+ isError: true,
100
+ };
101
+ }
102
+ const buffer = await imageResponse.arrayBuffer();
103
+ const base64Image = Buffer.from(buffer).toString("base64");
104
+ return {
105
+ content: [
106
+ {
107
+ type: "text",
108
+ text: `Generated poster for ${args.location}.`,
109
+ },
110
+ {
111
+ type: "image",
112
+ data: base64Image,
113
+ mimeType: "image/png",
114
+ },
115
+ ],
116
+ };
117
+ }
118
+ catch (error) {
119
+ return {
120
+ content: [{ type: "text", text: `Failed to connect to CartoArt API: ${error instanceof Error ? error.message : String(error)}` }],
121
+ isError: true,
122
+ };
123
+ }
124
+ }
125
+ throw new Error("Tool not found");
126
+ });
127
+ async function main() {
128
+ const transport = new StdioServerTransport();
129
+ await server.connect(transport);
130
+ console.error("CartoArt MCP server running on stdio");
131
+ }
132
+ main().catch((error) => {
133
+ console.error("Server error:", error);
134
+ process.exit(1);
135
+ });
136
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACH,qBAAqB,EACrB,sBAAsB,GACzB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,+CAA+C,CAAC;AAEjG,MAAM,MAAM,GAAG,IAAI,MAAM,CACrB;IACI,IAAI,EAAE,eAAe;IACr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O,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@kkingsbe/carto-art-mcp",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "carto-art-mcp": "dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "prepublishOnly": "npm run build",
15
+ "start": "node dist/index.js",
16
+ "dev": "ts-node index.ts",
17
+ "test": "echo \"Error: no test specified\" && exit 1"
18
+ },
19
+ "keywords": [],
20
+ "author": "",
21
+ "license": "ISC",
22
+ "description": "",
23
+ "dependencies": {
24
+ "@modelcontextprotocol/sdk": "^1.25.1",
25
+ "node-fetch": "^3.3.2",
26
+ "zod": "^4.3.4"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^25.0.3",
30
+ "ts-node": "^10.9.2",
31
+ "typescript": "^5.9.3"
32
+ }
33
+ }