@pipeworx/mcp-carbon-interface 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 +55 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +260 -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,55 @@
|
|
|
1
|
+
# mcp-carbon-interface
|
|
2
|
+
|
|
3
|
+
Carbon Interface MCP — Carbon Interface API (v1)
|
|
4
|
+
|
|
5
|
+
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 965+ live data sources.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"mcpServers": {
|
|
19
|
+
"carbon-interface": {
|
|
20
|
+
"url": "https://gateway.pipeworx.io/carbon-interface/mcp"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or connect to the full Pipeworx gateway for access to all 965+ data sources:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"pipeworx": {
|
|
32
|
+
"url": "https://gateway.pipeworx.io/mcp"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Using with ask_pipeworx
|
|
39
|
+
|
|
40
|
+
Instead of calling tools directly, you can ask questions in plain English:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
ask_pipeworx({ question: "your question about Carbon Interface data" })
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The gateway picks the right tool and fills the arguments automatically.
|
|
47
|
+
|
|
48
|
+
## More
|
|
49
|
+
|
|
50
|
+
- [All tools and guides](https://github.com/pipeworx-io/examples)
|
|
51
|
+
- [pipeworx.io](https://pipeworx.io)
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipeworx/mcp-carbon-interface",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Carbon Interface MCP — Carbon Interface API (v1)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "carbon-interface"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-carbon-interface"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"typecheck": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.pipeworx-io/carbon-interface",
|
|
4
|
+
"title": "Carbon Interface",
|
|
5
|
+
"description": "Carbon Interface MCP — Carbon Interface API (v1)",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/carbon-interface",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-carbon-interface",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/carbon-interface/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
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
|
+
meter?: { credits: number };
|
|
15
|
+
cost?: Record<string, unknown>;
|
|
16
|
+
provider?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Carbon Interface MCP — Carbon Interface API (v1)
|
|
21
|
+
*
|
|
22
|
+
* BYO key: requires a Carbon Interface API key from https://www.carboninterface.com/
|
|
23
|
+
* Passed via _apiKey parameter.
|
|
24
|
+
*
|
|
25
|
+
* Tools:
|
|
26
|
+
* - estimate_electricity: estimate CO2 emissions from electricity usage
|
|
27
|
+
* - estimate_flight: estimate CO2 emissions from a flight
|
|
28
|
+
* - estimate_vehicle: estimate CO2 emissions from vehicle travel
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const BASE_URL = 'https://www.carboninterface.com/api/v1';
|
|
33
|
+
|
|
34
|
+
// --- Helpers ---
|
|
35
|
+
|
|
36
|
+
function extractKey(args: Record<string, unknown>): string {
|
|
37
|
+
const key = args._apiKey as string;
|
|
38
|
+
delete args._apiKey;
|
|
39
|
+
if (!key) throw new Error('Carbon Interface API key required. Get one at https://www.carboninterface.com/ and pass via _apiKey.');
|
|
40
|
+
return key;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function ciPost(apiKey: string, body: Record<string, unknown>): Promise<unknown> {
|
|
44
|
+
const res = await fetch(`${BASE_URL}/estimates`, {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: {
|
|
47
|
+
'Content-Type': 'application/json',
|
|
48
|
+
Authorization: `Bearer ${apiKey}`,
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify(body),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (!res.ok) {
|
|
54
|
+
const text = await res.text();
|
|
55
|
+
throw new Error(`Carbon Interface API error (${res.status}): ${text}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const data = (await res.json()) as { data?: { attributes?: Record<string, unknown> } };
|
|
59
|
+
return data.data?.attributes ?? data;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// --- Raw API response type ---
|
|
63
|
+
|
|
64
|
+
type EstimateAttributes = {
|
|
65
|
+
country?: string | null;
|
|
66
|
+
state?: string | null;
|
|
67
|
+
electricity_unit?: string | null;
|
|
68
|
+
electricity_value?: number | null;
|
|
69
|
+
estimated_at?: string | null;
|
|
70
|
+
carbon_g?: number | null;
|
|
71
|
+
carbon_lb?: number | null;
|
|
72
|
+
carbon_kg?: number | null;
|
|
73
|
+
carbon_mt?: number | null;
|
|
74
|
+
distance_unit?: string | null;
|
|
75
|
+
distance_value?: number | null;
|
|
76
|
+
vehicle_make?: string | null;
|
|
77
|
+
vehicle_model?: string | null;
|
|
78
|
+
vehicle_year?: number | null;
|
|
79
|
+
vehicle_model_id?: string | null;
|
|
80
|
+
passengers?: number | null;
|
|
81
|
+
legs?: { departure_airport?: string; destination_airport?: string; class?: string }[] | null;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// --- Tool definitions ---
|
|
85
|
+
|
|
86
|
+
const tools: McpToolExport['tools'] = [
|
|
87
|
+
{
|
|
88
|
+
name: 'estimate_electricity',
|
|
89
|
+
description:
|
|
90
|
+
'Estimate CO2 emissions from electricity usage. Returns carbon emissions in grams, kg, and metric tons. Example: estimate_electricity(500, "us", "kwh") for 500 kWh in the US.',
|
|
91
|
+
inputSchema: {
|
|
92
|
+
type: 'object',
|
|
93
|
+
properties: {
|
|
94
|
+
_apiKey: { type: 'string', description: 'Carbon Interface API key' },
|
|
95
|
+
value: { type: 'number', description: 'Amount of electricity consumed (e.g., 500)' },
|
|
96
|
+
country: { type: 'string', description: 'ISO 3166-1 alpha-2 country code (e.g., "us", "gb", "de")' },
|
|
97
|
+
unit: { type: 'string', description: 'Unit of electricity: "kwh" or "mwh" (default: "kwh")' },
|
|
98
|
+
state: { type: 'string', description: 'US state code for more precise estimate (e.g., "ca", "ny"). Only for US.' },
|
|
99
|
+
},
|
|
100
|
+
required: ['_apiKey', 'value', 'country'],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'estimate_flight',
|
|
105
|
+
description:
|
|
106
|
+
'Estimate CO2 emissions from a flight. Provide number of passengers and flight legs (departure/arrival airport IATA codes). Returns per-passenger and total carbon emissions. Example: estimate_flight(2, [{"departure_airport": "SFO", "destination_airport": "JFK"}]).',
|
|
107
|
+
inputSchema: {
|
|
108
|
+
type: 'object',
|
|
109
|
+
properties: {
|
|
110
|
+
_apiKey: { type: 'string', description: 'Carbon Interface API key' },
|
|
111
|
+
passengers: { type: 'number', description: 'Number of passengers (e.g., 2)' },
|
|
112
|
+
legs: {
|
|
113
|
+
type: 'array',
|
|
114
|
+
description: 'Array of flight legs with IATA airport codes',
|
|
115
|
+
items: {
|
|
116
|
+
type: 'object',
|
|
117
|
+
properties: {
|
|
118
|
+
departure_airport: { type: 'string', description: 'Departure airport IATA code (e.g., "SFO")' },
|
|
119
|
+
destination_airport: { type: 'string', description: 'Arrival airport IATA code (e.g., "JFK")' },
|
|
120
|
+
cabin_class: { type: 'string', description: 'Cabin class: "economy", "premium", or "business" (optional)' },
|
|
121
|
+
},
|
|
122
|
+
required: ['departure_airport', 'destination_airport'],
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
required: ['_apiKey', 'passengers', 'legs'],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'estimate_vehicle',
|
|
131
|
+
description:
|
|
132
|
+
'Estimate CO2 emissions from driving a vehicle. Provide distance and a vehicle model ID (from Carbon Interface). Returns carbon emissions in grams, kg, and metric tons. Example: estimate_vehicle(100, "7268a9b7-17e8-4c8d-acca-57059252afe9", "mi").',
|
|
133
|
+
inputSchema: {
|
|
134
|
+
type: 'object',
|
|
135
|
+
properties: {
|
|
136
|
+
_apiKey: { type: 'string', description: 'Carbon Interface API key' },
|
|
137
|
+
distance: { type: 'number', description: 'Distance traveled (e.g., 100)' },
|
|
138
|
+
vehicle_model_id: { type: 'string', description: 'Carbon Interface vehicle model UUID' },
|
|
139
|
+
unit: { type: 'string', description: 'Distance unit: "mi" or "km" (default: "mi")' },
|
|
140
|
+
},
|
|
141
|
+
required: ['_apiKey', 'distance', 'vehicle_model_id'],
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
// --- callTool dispatcher ---
|
|
147
|
+
|
|
148
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
149
|
+
const key = extractKey(args);
|
|
150
|
+
|
|
151
|
+
switch (name) {
|
|
152
|
+
case 'estimate_electricity':
|
|
153
|
+
return estimateElectricity(
|
|
154
|
+
key,
|
|
155
|
+
args.value as number,
|
|
156
|
+
args.country as string,
|
|
157
|
+
(args.unit as string) ?? 'kwh',
|
|
158
|
+
args.state as string | undefined,
|
|
159
|
+
);
|
|
160
|
+
case 'estimate_flight':
|
|
161
|
+
return estimateFlight(
|
|
162
|
+
key,
|
|
163
|
+
args.passengers as number,
|
|
164
|
+
args.legs as { departure_airport: string; destination_airport: string; cabin_class?: string }[],
|
|
165
|
+
);
|
|
166
|
+
case 'estimate_vehicle':
|
|
167
|
+
return estimateVehicle(
|
|
168
|
+
key,
|
|
169
|
+
args.distance as number,
|
|
170
|
+
args.vehicle_model_id as string,
|
|
171
|
+
(args.unit as string) ?? 'mi',
|
|
172
|
+
);
|
|
173
|
+
default:
|
|
174
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// --- Tool implementations ---
|
|
179
|
+
|
|
180
|
+
async function estimateElectricity(apiKey: string, value: number, country: string, unit: string, state?: string) {
|
|
181
|
+
const body: Record<string, unknown> = {
|
|
182
|
+
type: 'electricity',
|
|
183
|
+
electricity_unit: unit,
|
|
184
|
+
electricity_value: value,
|
|
185
|
+
country: country.toLowerCase(),
|
|
186
|
+
};
|
|
187
|
+
if (state) body.state = state.toLowerCase();
|
|
188
|
+
|
|
189
|
+
const attrs = (await ciPost(apiKey, body)) as EstimateAttributes;
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
electricity_value: attrs.electricity_value ?? value,
|
|
193
|
+
electricity_unit: attrs.electricity_unit ?? unit,
|
|
194
|
+
country: attrs.country ?? country,
|
|
195
|
+
state: attrs.state ?? state ?? null,
|
|
196
|
+
estimated_at: attrs.estimated_at ?? null,
|
|
197
|
+
carbon_g: attrs.carbon_g ?? null,
|
|
198
|
+
carbon_kg: attrs.carbon_kg ?? null,
|
|
199
|
+
carbon_mt: attrs.carbon_mt ?? null,
|
|
200
|
+
carbon_lb: attrs.carbon_lb ?? null,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function estimateFlight(
|
|
205
|
+
apiKey: string,
|
|
206
|
+
passengers: number,
|
|
207
|
+
legs: { departure_airport: string; destination_airport: string; cabin_class?: string }[],
|
|
208
|
+
) {
|
|
209
|
+
const body = {
|
|
210
|
+
type: 'flight',
|
|
211
|
+
passengers,
|
|
212
|
+
legs: legs.map((l) => ({
|
|
213
|
+
departure_airport: l.departure_airport.toUpperCase(),
|
|
214
|
+
destination_airport: l.destination_airport.toUpperCase(),
|
|
215
|
+
...(l.cabin_class ? { cabin_class: l.cabin_class } : {}),
|
|
216
|
+
})),
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const attrs = (await ciPost(apiKey, body)) as EstimateAttributes;
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
passengers: attrs.passengers ?? passengers,
|
|
223
|
+
legs: (attrs.legs ?? []).map((l) => ({
|
|
224
|
+
departure_airport: l.departure_airport ?? null,
|
|
225
|
+
destination_airport: l.destination_airport ?? null,
|
|
226
|
+
cabin_class: l.class ?? null,
|
|
227
|
+
})),
|
|
228
|
+
estimated_at: attrs.estimated_at ?? null,
|
|
229
|
+
carbon_g: attrs.carbon_g ?? null,
|
|
230
|
+
carbon_kg: attrs.carbon_kg ?? null,
|
|
231
|
+
carbon_mt: attrs.carbon_mt ?? null,
|
|
232
|
+
carbon_lb: attrs.carbon_lb ?? null,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function estimateVehicle(apiKey: string, distance: number, vehicleModelId: string, unit: string) {
|
|
237
|
+
const body = {
|
|
238
|
+
type: 'vehicle',
|
|
239
|
+
distance_unit: unit,
|
|
240
|
+
distance_value: distance,
|
|
241
|
+
vehicle_model_id: vehicleModelId,
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const attrs = (await ciPost(apiKey, body)) as EstimateAttributes;
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
distance_value: attrs.distance_value ?? distance,
|
|
248
|
+
distance_unit: attrs.distance_unit ?? unit,
|
|
249
|
+
vehicle_make: attrs.vehicle_make ?? null,
|
|
250
|
+
vehicle_model: attrs.vehicle_model ?? null,
|
|
251
|
+
vehicle_year: attrs.vehicle_year ?? null,
|
|
252
|
+
estimated_at: attrs.estimated_at ?? null,
|
|
253
|
+
carbon_g: attrs.carbon_g ?? null,
|
|
254
|
+
carbon_kg: attrs.carbon_kg ?? null,
|
|
255
|
+
carbon_mt: attrs.carbon_mt ?? null,
|
|
256
|
+
carbon_lb: attrs.carbon_lb ?? null,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export default { tools, callTool, meter: { credits: 5 } } 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
|
+
}
|