@pipeworx/mcp-carbon 0.1.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/LICENSE +21 -0
- package/README.md +34 -0
- package/package.json +20 -0
- package/server.json +25 -0
- package/src/index.ts +170 -0
- package/tsconfig.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pipeworx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# mcp-carbon
|
|
2
|
+
|
|
3
|
+
Carbon MCP — UK Carbon Intensity API (free, no auth)
|
|
4
|
+
|
|
5
|
+
Part of the [Pipeworx](https://pipeworx.io) open MCP gateway.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
Add to your MCP client config:
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"mcpServers": {
|
|
19
|
+
"carbon": {
|
|
20
|
+
"url": "https://gateway.pipeworx.io/carbon/mcp"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or use the CLI:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx pipeworx use carbon
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipeworx/mcp-carbon",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Carbon MCP — UK Carbon Intensity API (free, no auth)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "carbon"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-carbon"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"typecheck": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.pipeworx-io/carbon",
|
|
4
|
+
"title": "caruon",
|
|
5
|
+
"description": "Carbon MCP — UK Carbon Intensity API (free, no auth)",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/carbon",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-carbon",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"packages": [
|
|
13
|
+
{
|
|
14
|
+
"registryType": "npm",
|
|
15
|
+
"identifier": "@pipeworx/mcp-carbon",
|
|
16
|
+
"version": "0.1.0"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"remotes": [
|
|
20
|
+
{
|
|
21
|
+
"type": "streamable-http",
|
|
22
|
+
"url": "https://gateway.pipeworx.io/carbon/mcp"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
interface McpToolDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: 'object';
|
|
6
|
+
properties: Record<string, unknown>;
|
|
7
|
+
required?: string[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface McpToolExport {
|
|
12
|
+
tools: McpToolDefinition[];
|
|
13
|
+
callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Carbon MCP — UK Carbon Intensity API (free, no auth)
|
|
18
|
+
*
|
|
19
|
+
* Tools:
|
|
20
|
+
* - get_intensity: current national carbon intensity (forecast, actual, index)
|
|
21
|
+
* - get_intensity_by_date: carbon intensity for a specific date (YYYY-MM-DD)
|
|
22
|
+
* - get_generation_mix: current electricity generation mix by fuel type
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const BASE_URL = 'https://api.carbonintensity.org.uk';
|
|
27
|
+
|
|
28
|
+
const tools: McpToolExport['tools'] = [
|
|
29
|
+
{
|
|
30
|
+
name: 'get_intensity',
|
|
31
|
+
description:
|
|
32
|
+
'Get the current UK national carbon intensity. Returns the forecast value (gCO2/kWh), actual measured value, and a qualitative index (very low / low / moderate / high / very high).',
|
|
33
|
+
inputSchema: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'get_intensity_by_date',
|
|
40
|
+
description:
|
|
41
|
+
'Get UK carbon intensity data for every half-hour period of a given date. Returns an array of time-window entries each with forecast and actual gCO2/kWh values.',
|
|
42
|
+
inputSchema: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
date: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
description: 'Date in YYYY-MM-DD format (e.g., 2024-03-15)',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: ['date'],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'get_generation_mix',
|
|
55
|
+
description:
|
|
56
|
+
'Get the current UK electricity generation mix showing the percentage contribution of each fuel type (gas, coal, wind, solar, nuclear, hydro, biomass, imports, etc.).',
|
|
57
|
+
inputSchema: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
65
|
+
switch (name) {
|
|
66
|
+
case 'get_intensity':
|
|
67
|
+
return getIntensity();
|
|
68
|
+
case 'get_intensity_by_date':
|
|
69
|
+
return getIntensityByDate(args.date as string);
|
|
70
|
+
case 'get_generation_mix':
|
|
71
|
+
return getGenerationMix();
|
|
72
|
+
default:
|
|
73
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function getIntensity() {
|
|
78
|
+
const res = await fetch(`${BASE_URL}/intensity`, {
|
|
79
|
+
headers: { Accept: 'application/json' },
|
|
80
|
+
});
|
|
81
|
+
if (!res.ok) throw new Error(`Carbon Intensity API error: ${res.status}`);
|
|
82
|
+
|
|
83
|
+
const data = (await res.json()) as {
|
|
84
|
+
data: {
|
|
85
|
+
from: string;
|
|
86
|
+
to: string;
|
|
87
|
+
intensity: {
|
|
88
|
+
forecast: number;
|
|
89
|
+
actual: number | null;
|
|
90
|
+
index: string;
|
|
91
|
+
};
|
|
92
|
+
}[];
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const entry = data.data[0];
|
|
96
|
+
if (!entry) throw new Error('No intensity data returned');
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
from: entry.from,
|
|
100
|
+
to: entry.to,
|
|
101
|
+
forecast_gco2_per_kwh: entry.intensity.forecast,
|
|
102
|
+
actual_gco2_per_kwh: entry.intensity.actual,
|
|
103
|
+
index: entry.intensity.index,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function getIntensityByDate(date: string) {
|
|
108
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
|
|
109
|
+
throw new Error('Date must be in YYYY-MM-DD format');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const res = await fetch(`${BASE_URL}/intensity/date/${encodeURIComponent(date)}`, {
|
|
113
|
+
headers: { Accept: 'application/json' },
|
|
114
|
+
});
|
|
115
|
+
if (!res.ok) throw new Error(`Carbon Intensity API error: ${res.status}`);
|
|
116
|
+
|
|
117
|
+
const data = (await res.json()) as {
|
|
118
|
+
data: {
|
|
119
|
+
from: string;
|
|
120
|
+
to: string;
|
|
121
|
+
intensity: {
|
|
122
|
+
forecast: number;
|
|
123
|
+
actual: number | null;
|
|
124
|
+
index: string;
|
|
125
|
+
};
|
|
126
|
+
}[];
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
date,
|
|
131
|
+
periods: data.data.map((entry) => ({
|
|
132
|
+
from: entry.from,
|
|
133
|
+
to: entry.to,
|
|
134
|
+
forecast_gco2_per_kwh: entry.intensity.forecast,
|
|
135
|
+
actual_gco2_per_kwh: entry.intensity.actual,
|
|
136
|
+
index: entry.intensity.index,
|
|
137
|
+
})),
|
|
138
|
+
count: data.data.length,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function getGenerationMix() {
|
|
143
|
+
const res = await fetch(`${BASE_URL}/generation`, {
|
|
144
|
+
headers: { Accept: 'application/json' },
|
|
145
|
+
});
|
|
146
|
+
if (!res.ok) throw new Error(`Carbon Intensity API error: ${res.status}`);
|
|
147
|
+
|
|
148
|
+
const data = (await res.json()) as {
|
|
149
|
+
data: {
|
|
150
|
+
from: string;
|
|
151
|
+
to: string;
|
|
152
|
+
generationmix: {
|
|
153
|
+
fuel: string;
|
|
154
|
+
perc: number;
|
|
155
|
+
}[];
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const entry = data.data;
|
|
160
|
+
return {
|
|
161
|
+
from: entry.from,
|
|
162
|
+
to: entry.to,
|
|
163
|
+
generation_mix: entry.generationmix.map((g) => ({
|
|
164
|
+
fuel: g.fuel,
|
|
165
|
+
percentage: g.perc,
|
|
166
|
+
})),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export default { tools, callTool } satisfies McpToolExport;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"rootDir": "src",
|
|
11
|
+
"declaration": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|