citybikes-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.
- package/README.md +21 -0
- package/dist/api.js +51 -0
- package/dist/index.js +4 -0
- package/dist/server.js +38 -0
- package/package.json +44 -0
- package/server.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# CityBikes MCP
|
|
2
|
+
|
|
3
|
+
List bike share networks and read live station availability from the public CityBikes API. No key required.
|
|
4
|
+
|
|
5
|
+
This file is self contained. It reads public data only and never writes to the machine. All output is bounded and honest about what could not be fetched.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
* `networks` All networks.
|
|
11
|
+
* `network` Live stations for one network.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install
|
|
17
|
+
npm run build
|
|
18
|
+
node dist/index.js
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Data comes from the public CityBikes aggregation API.
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const BASE = "https://api.citybik.es/v2";
|
|
2
|
+
const UA = "mrfentmen-citybikes-mcp/1.0 (https://github.com/mrfentmen)";
|
|
3
|
+
export class CitybikesError extends Error {
|
|
4
|
+
}
|
|
5
|
+
async function get(url) {
|
|
6
|
+
const res = await fetch(url, {
|
|
7
|
+
headers: { "User-Agent": UA, Accept: "application/json" },
|
|
8
|
+
signal: AbortSignal.timeout(30000),
|
|
9
|
+
});
|
|
10
|
+
if (!res.ok)
|
|
11
|
+
throw new CitybikesError(`CityBikes returned HTTP ${res.status}`);
|
|
12
|
+
return (await res.json());
|
|
13
|
+
}
|
|
14
|
+
export async function networks(_args) {
|
|
15
|
+
const d = await get(`${BASE}/networks`);
|
|
16
|
+
const nets = (d?.networks ?? []);
|
|
17
|
+
if (!nets.length)
|
|
18
|
+
return "No networks found";
|
|
19
|
+
const lines = nets.map((n, i) => {
|
|
20
|
+
const loc = n?.location ?? {};
|
|
21
|
+
return `${i + 1}. ${n?.name ?? "n/a"} (${n?.id ?? "n/a"}) | ${loc?.city ?? ""}, ${loc?.country ?? ""}`;
|
|
22
|
+
});
|
|
23
|
+
return `Bike share networks (${nets.length} total, showing first 50):\n` + lines.slice(0, 50).join("\n");
|
|
24
|
+
}
|
|
25
|
+
export async function network(args) {
|
|
26
|
+
const id = (args.id ?? "").trim();
|
|
27
|
+
if (!id)
|
|
28
|
+
throw new CitybikesError("Provide a network ID like bixi-montreal");
|
|
29
|
+
const d = await get(`${BASE}/networks/${encodeURIComponent(id)}`);
|
|
30
|
+
const n = d?.network;
|
|
31
|
+
if (!n)
|
|
32
|
+
throw new CitybikesError(`Network not found: ${id}`);
|
|
33
|
+
const stations = (n?.stations ?? []);
|
|
34
|
+
if (!stations.length)
|
|
35
|
+
return `${n?.name ?? id}: network found but no stations reported`;
|
|
36
|
+
const total = stations.length;
|
|
37
|
+
const withBikes = stations.filter((s) => (s?.free_bikes ?? 0) > 0).length;
|
|
38
|
+
const lines = [
|
|
39
|
+
`${n?.name ?? id} | ${n?.location?.city ?? ""}, ${n?.location?.country ?? ""}`,
|
|
40
|
+
`${total} stations, ${withBikes} with bikes available`,
|
|
41
|
+
"",
|
|
42
|
+
...stations.slice(0, 20).map((s, i) => {
|
|
43
|
+
const bikes = s?.free_bikes ?? 0;
|
|
44
|
+
const slots = s?.empty_slots ?? 0;
|
|
45
|
+
return `${i + 1}. ${s?.name ?? "n/a"} | bikes ${bikes} | slots ${slots}`;
|
|
46
|
+
}),
|
|
47
|
+
];
|
|
48
|
+
if (total > 20)
|
|
49
|
+
lines.push(`... and ${total - 20} more stations`);
|
|
50
|
+
return lines.join("\n");
|
|
51
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
2
|
+
import { createServer } from "./server.js";
|
|
3
|
+
const main = async () => { const server = createServer(); await server.connect(new StdioServerTransport()); };
|
|
4
|
+
main().catch((error) => { console.error("Fatal error:", error); process.exit(1); });
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { network } from "./api.js";
|
|
4
|
+
import { networks } from "./api.js";
|
|
5
|
+
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
6
|
+
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
7
|
+
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
8
|
+
const error = (e) => `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
9
|
+
export function createServer() {
|
|
10
|
+
const server = new McpServer({ name: "citybikes-mcp", version: "1.0.0" });
|
|
11
|
+
server.registerTool("networks", {
|
|
12
|
+
title: "Networks",
|
|
13
|
+
description: "All bike share networks.",
|
|
14
|
+
inputSchema: z.object({}),
|
|
15
|
+
annotations: READ_ONLY,
|
|
16
|
+
}, async (args) => {
|
|
17
|
+
try {
|
|
18
|
+
return text(await networks(args));
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
return textError(error(e));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
server.registerTool("network", {
|
|
25
|
+
title: "Network",
|
|
26
|
+
description: "Live stations for one network.",
|
|
27
|
+
inputSchema: z.object({ id: z.string().describe("Network ID like bixi-montreal.") }),
|
|
28
|
+
annotations: READ_ONLY,
|
|
29
|
+
}, async (args) => {
|
|
30
|
+
try {
|
|
31
|
+
return text(await network(args));
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return textError(error(e));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return server;
|
|
38
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/mrfentmen/citybikes-mcp.git"
|
|
7
|
+
},
|
|
8
|
+
"bin": {
|
|
9
|
+
"citybikes-mcp": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"server.json",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"start": "node dist/index.js",
|
|
20
|
+
"dev": "npm run build && node dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
25
|
+
"zod": "^3.23.8"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
29
|
+
"typescript": "^5.6.0"
|
|
30
|
+
},
|
|
31
|
+
"name": "citybikes-mcp",
|
|
32
|
+
"description": "List bike share networks and live station availability from CityBikes. No key required.",
|
|
33
|
+
"mcpName": "io.github.mrfentmen/citybikes-mcp",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"mcp",
|
|
36
|
+
"bikes",
|
|
37
|
+
"transit",
|
|
38
|
+
"stations",
|
|
39
|
+
"city"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.mrfentmen/citybikes-mcp",
|
|
4
|
+
"description": "List bike share networks and live station availability from CityBikes. No key required.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/mrfentmen/citybikes-mcp",
|
|
7
|
+
"source": "github"
|
|
8
|
+
},
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"packages": [
|
|
11
|
+
{
|
|
12
|
+
"registryType": "npm",
|
|
13
|
+
"identifier": "citybikes-mcp",
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"transport": {
|
|
16
|
+
"type": "stdio"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|