envirocar-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 +22 -0
- package/dist/api.js +45 -0
- package/dist/index.js +4 -0
- package/dist/server.js +52 -0
- package/package.json +45 -0
- package/server.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Envirocar MCP
|
|
2
|
+
|
|
3
|
+
enviroCar open environmental car tracking data. 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
|
+
* `tracks` List recent tracks.
|
|
11
|
+
* `track_detail` Get a track by id.
|
|
12
|
+
* `sensors` List available sensor definitions.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install
|
|
18
|
+
npm run build
|
|
19
|
+
node dist/index.js
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Data comes from the public Envirocar API.
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const UA = 'mrfentmen-envirocar-mcp/1.0';
|
|
2
|
+
const BASE = 'https://envirocar.org/api/stable';
|
|
3
|
+
export async function tracks(args) {
|
|
4
|
+
const limit = Math.min(Math.max(Number(args?.limit ?? 5) || 5, 1), 20);
|
|
5
|
+
const res = await fetch(`${BASE}/tracks?limit=${limit}`, {
|
|
6
|
+
headers: { 'User-Agent': UA, Accept: 'application/json' },
|
|
7
|
+
signal: AbortSignal.timeout(25000),
|
|
8
|
+
});
|
|
9
|
+
if (!res.ok)
|
|
10
|
+
throw new Error(`enviroCar returned ${res.status}`);
|
|
11
|
+
const d = (await res.json());
|
|
12
|
+
const list = d.tracks ?? [];
|
|
13
|
+
if (!list.length)
|
|
14
|
+
return 'No tracks returned.';
|
|
15
|
+
return `Recent enviroCar tracks (${list.length} shown):\n` + list.map((t, i) => {
|
|
16
|
+
const km = t.length != null ? (t.length / 1000).toFixed(2) : '?';
|
|
17
|
+
return `${i + 1}. ${t.id ?? '?'} | ${km} km | ${t.begin ?? '?'} to ${t.end ?? '?'} | sensor ${t.sensor?.properties?.model ?? t.sensor?.type ?? '?'}`;
|
|
18
|
+
}).join('\n');
|
|
19
|
+
}
|
|
20
|
+
export async function trackDetail(args) {
|
|
21
|
+
const res = await fetch(`${BASE}/tracks/${encodeURIComponent(args.id)}`, {
|
|
22
|
+
headers: { 'User-Agent': UA, Accept: 'application/json' },
|
|
23
|
+
signal: AbortSignal.timeout(25000),
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok)
|
|
26
|
+
throw new Error(`enviroCar returned ${res.status}`);
|
|
27
|
+
const d = (await res.json());
|
|
28
|
+
if (!d.id)
|
|
29
|
+
throw new Error('No track returned.');
|
|
30
|
+
const props = d.properties ?? [];
|
|
31
|
+
const first = d.geometry?.coordinates?.[0];
|
|
32
|
+
return `Track ${d.id}\nBegin: ${d.begin ?? '?'}\nEnd: ${d.end ?? '?'}\nLength: ${d.length != null ? `${(d.length / 1000).toFixed(2)} km` : '?'}\nStart: ${first ? `${first[1].toFixed(5)}, ${first[0].toFixed(5)}` : '?'}\nSensor: ${d.sensor?.properties?.manufacturer ?? ''} ${d.sensor?.properties?.model ?? ''} (${d.sensor?.type ?? '?'})\nMeasurements: ${props.length}\nSample: ${props.slice(0, 8).map((p) => `${p.name}=${p.value}${p.unit ? p.unit : ''}`).join(', ') || 'none'}`;
|
|
33
|
+
}
|
|
34
|
+
export async function sensors(_args) {
|
|
35
|
+
const res = await fetch(`${BASE}/sensors`, {
|
|
36
|
+
headers: { 'User-Agent': UA, Accept: 'application/json' },
|
|
37
|
+
signal: AbortSignal.timeout(25000),
|
|
38
|
+
});
|
|
39
|
+
if (!res.ok)
|
|
40
|
+
throw new Error(`enviroCar returned ${res.status}`);
|
|
41
|
+
const d = (await res.json());
|
|
42
|
+
if (!Array.isArray(d) || !d.length)
|
|
43
|
+
return 'No sensors returned.';
|
|
44
|
+
return `enviroCar sensors (${d.length}):\n` + d.map((s) => `* ${s.name ?? '?'} (${s.quantity ?? '?'}) [${s.unit ?? '?'}]`).join('\n');
|
|
45
|
+
}
|
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,52 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { sensors } from "./api.js";
|
|
4
|
+
import { trackDetail } from "./api.js";
|
|
5
|
+
import { tracks } from "./api.js";
|
|
6
|
+
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
7
|
+
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
8
|
+
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
9
|
+
const error = (e) => `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
10
|
+
export function createServer() {
|
|
11
|
+
const server = new McpServer({ name: "envirocar-mcp", version: "1.0.0" });
|
|
12
|
+
server.registerTool("tracks", {
|
|
13
|
+
title: "Tracks",
|
|
14
|
+
description: "List recent tracks.",
|
|
15
|
+
inputSchema: z.object({ limit: z.number().describe("Max tracks.").optional() }),
|
|
16
|
+
annotations: READ_ONLY,
|
|
17
|
+
}, async (args) => {
|
|
18
|
+
try {
|
|
19
|
+
return text(await tracks(args));
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
return textError(error(e));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
server.registerTool("track_detail", {
|
|
26
|
+
title: "Track detail",
|
|
27
|
+
description: "Get a track by id.",
|
|
28
|
+
inputSchema: z.object({ id: z.string().describe("Track id.") }),
|
|
29
|
+
annotations: READ_ONLY,
|
|
30
|
+
}, async (args) => {
|
|
31
|
+
try {
|
|
32
|
+
return text(await trackDetail(args));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
return textError(error(e));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
server.registerTool("sensors", {
|
|
39
|
+
title: "Sensors",
|
|
40
|
+
description: "List available sensor definitions.",
|
|
41
|
+
inputSchema: z.object({}),
|
|
42
|
+
annotations: READ_ONLY,
|
|
43
|
+
}, async (args) => {
|
|
44
|
+
try {
|
|
45
|
+
return text(await sensors(args));
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
return textError(error(e));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return server;
|
|
52
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/mrfentmen/envirocar-mcp.git"
|
|
7
|
+
},
|
|
8
|
+
"bin": {
|
|
9
|
+
"envirocar-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": "envirocar-mcp",
|
|
32
|
+
"description": "enviroCar open environmental car tracking data.",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"mcp",
|
|
35
|
+
"envirocar",
|
|
36
|
+
"environment",
|
|
37
|
+
"car",
|
|
38
|
+
"gps",
|
|
39
|
+
"tracking"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"mcpName": "io.github.mrfentmen/envirocar-mcp"
|
|
45
|
+
}
|
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/envirocar-mcp",
|
|
4
|
+
"description": "enviroCar open environmental car tracking data.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/mrfentmen/envirocar-mcp",
|
|
7
|
+
"source": "github"
|
|
8
|
+
},
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"packages": [
|
|
11
|
+
{
|
|
12
|
+
"registryType": "npm",
|
|
13
|
+
"identifier": "envirocar-mcp",
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"transport": {
|
|
16
|
+
"type": "stdio"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|