@randomknights/aieds-mcp 0.0.0-stage → 2.5.1
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 +227 -0
- package/LICENSE-DOCS +51 -0
- package/NOTICE +35 -0
- package/README.md +49 -2
- package/mcp/dist/estimate.js +58 -0
- package/mcp/dist/factors.js +88 -0
- package/mcp/dist/index.js +139 -0
- package/mcp/dist/water.js +78 -0
- package/package.json +51 -4
- package/spec/aieds.schema.json +290 -0
- package/spec/v2/aieds-factors.json +643 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Random Knights, LLC
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
203
|
+
-------------------------------------------------------------------------------
|
|
204
|
+
|
|
205
|
+
Scope in this repository
|
|
206
|
+
|
|
207
|
+
This LICENSE (Apache 2.0) applies to the code and the schema:
|
|
208
|
+
|
|
209
|
+
lib/ AiEDs reference library (TypeScript)
|
|
210
|
+
mcp/ AiEDs MCP server (TypeScript), except
|
|
211
|
+
its README.md
|
|
212
|
+
spec/aieds.schema.json the AiEDs JSON Schema
|
|
213
|
+
spec/examples/validate.mjs the example conformance script
|
|
214
|
+
spec/test/ the spec and site gates
|
|
215
|
+
spec/measurements/*/harness/ the measurement harness code
|
|
216
|
+
eplus/v1/conformance/ the E+ conformance checker, except its
|
|
217
|
+
README.md
|
|
218
|
+
scripts/ build and release scripts
|
|
219
|
+
packages/ the npm package manifests and code,
|
|
220
|
+
except the README files
|
|
221
|
+
.github/ CI and release workflows
|
|
222
|
+
|
|
223
|
+
It does not apply to the standards' prose, the published coefficient tables,
|
|
224
|
+
or the other documents and data that describe or parameterize the standards.
|
|
225
|
+
Those are licensed CC BY 4.0 under LICENSE-DOCS; see that file, NOTICE, and
|
|
226
|
+
README.md for the exact path list. A file not listed in either file follows
|
|
227
|
+
the same split: code is Apache 2.0, prose and data are CC BY 4.0.
|
package/LICENSE-DOCS
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
AiEDs specification text, coefficient tables
|
|
2
|
+
Copyright 2026 Random Knights, LLC
|
|
3
|
+
|
|
4
|
+
Licensed under CC BY 4.0 (Creative Commons Attribution 4.0 International).
|
|
5
|
+
|
|
6
|
+
Full legal text: https://creativecommons.org/licenses/by/4.0/legalcode
|
|
7
|
+
Human-readable summary: https://creativecommons.org/licenses/by/4.0/
|
|
8
|
+
|
|
9
|
+
You are free to:
|
|
10
|
+
|
|
11
|
+
Share - copy and redistribute the material in any medium or format.
|
|
12
|
+
Adapt - remix, transform, and build upon the material for any purpose,
|
|
13
|
+
even commercially.
|
|
14
|
+
|
|
15
|
+
Under the following terms:
|
|
16
|
+
|
|
17
|
+
Attribution - You must give appropriate credit, provide a link to the
|
|
18
|
+
license, and indicate if changes were made. You may do so in
|
|
19
|
+
any reasonable manner, but not in any way that suggests the
|
|
20
|
+
licensor endorses you or your use.
|
|
21
|
+
|
|
22
|
+
No additional restrictions - You may not apply legal terms or
|
|
23
|
+
technological measures that legally restrict others from
|
|
24
|
+
doing anything the license permits.
|
|
25
|
+
|
|
26
|
+
No warranties are given. The license may not give you all of the permissions
|
|
27
|
+
necessary for your intended use. For example, other rights such as publicity,
|
|
28
|
+
privacy, or moral rights may limit how you use the material.
|
|
29
|
+
|
|
30
|
+
-------------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
Scope in this repository
|
|
33
|
+
|
|
34
|
+
This license applies to the standards' prose and to the documents and data
|
|
35
|
+
that describe or parameterize them:
|
|
36
|
+
|
|
37
|
+
spec/methodology.md the AiEDs methodology text
|
|
38
|
+
spec/v2/aieds-factors.json the published AiEDs coefficient tables
|
|
39
|
+
spec/v2/standard-versions.json the published standard version index
|
|
40
|
+
spec/examples/*.json the bundled AiEDs example records
|
|
41
|
+
spec/measurements/ method documents, configuration, raw
|
|
42
|
+
samples and summaries (not harness/)
|
|
43
|
+
eplus/v1/methodology.md the E+ methodology text
|
|
44
|
+
eplus/v1/conformance/README.md the E+ conformance checker guide
|
|
45
|
+
README.md, CONTRIBUTING.md, repository documentation
|
|
46
|
+
docs/, mcp/README.md,
|
|
47
|
+
packages/*/README.md
|
|
48
|
+
|
|
49
|
+
It does not apply to the reference library, the MCP server, the JSON Schema,
|
|
50
|
+
or any other code. Those are licensed Apache 2.0
|
|
51
|
+
under LICENSE; see that file, NOTICE, and README.md for the exact path list.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Random Knights standards: AiEDs and E+
|
|
2
|
+
Copyright 2026 Random Knights, LLC
|
|
3
|
+
|
|
4
|
+
This repository and the npm packages built from it carry two licenses, split
|
|
5
|
+
by what a file is, not by which directory it sits in:
|
|
6
|
+
|
|
7
|
+
Code and the AiEDs JSON Schema Apache License 2.0, see LICENSE
|
|
8
|
+
Standards text, tables and data CC BY 4.0, see LICENSE-DOCS
|
|
9
|
+
|
|
10
|
+
LICENSE and LICENSE-DOCS each end with the exact path list they cover.
|
|
11
|
+
README.md, section LICENSE, carries the same list as a table.
|
|
12
|
+
|
|
13
|
+
npm packages built from this repository:
|
|
14
|
+
|
|
15
|
+
@randomknights/aieds the AiEDs reference library (Apache 2.0), the AiEDs
|
|
16
|
+
JSON Schema (Apache 2.0) and the published coefficient
|
|
17
|
+
tables (CC BY 4.0). SPDX: Apache-2.0 AND CC-BY-4.0
|
|
18
|
+
@randomknights/aieds-mcp
|
|
19
|
+
the AiEDs MCP server (Apache 2.0), the AiEDs JSON
|
|
20
|
+
Schema (Apache 2.0) and the published coefficient
|
|
21
|
+
tables (CC BY 4.0). SPDX: Apache-2.0 AND CC-BY-4.0
|
|
22
|
+
@randomknights/earthplus
|
|
23
|
+
the E+ conformance checker (Apache 2.0) and the E+
|
|
24
|
+
methodology text, methodology.md (CC BY 4.0).
|
|
25
|
+
SPDX: Apache-2.0 AND CC-BY-4.0
|
|
26
|
+
|
|
27
|
+
Attribution for the CC BY 4.0 material: "Random Knights, LLC", the title of the
|
|
28
|
+
standard and its version, and a link to https://github.com/random-knights/standard
|
|
29
|
+
or https://standard.rand0m.ai. The CITATION files give the preferred citation.
|
|
30
|
+
|
|
31
|
+
Third-party material: none is bundled in this repository or in the packages.
|
|
32
|
+
Dependencies are installed from the npm registry under their own licenses and
|
|
33
|
+
are not redistributed here. The AiEDs coefficient tables state published
|
|
34
|
+
figures as numbers with their citations; they are not copies of the cited
|
|
35
|
+
works.
|
package/README.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @randomknights/aieds-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An MCP server for the [AI Energy Disclosure Standard (AiEDs)](https://standard.rand0m.ai), methodology 2.5.1. It gives an agent three tools over stdio. It needs no key and makes no network call.
|
|
4
|
+
|
|
5
|
+
The package version is the methodology version it implements. The coefficients are the published AiEDs factor table, shipped inside the package, not a second copy.
|
|
6
|
+
|
|
7
|
+
## Add it to an MCP client
|
|
8
|
+
|
|
9
|
+
Most clients take a block like this (for example Claude Desktop's `claude_desktop_config.json`):
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"mcpServers": {
|
|
14
|
+
"aieds": {
|
|
15
|
+
"command": "npx",
|
|
16
|
+
"args": ["-y", "@randomknights/aieds-mcp"]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
In Claude Code:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
claude mcp add aieds -- npx -y @randomknights/aieds-mcp
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Node.js 20 or newer is needed.
|
|
29
|
+
|
|
30
|
+
## Tools
|
|
31
|
+
|
|
32
|
+
- **`aieds_estimate`**: compute metrics in (`gpuSeconds` with a hardware key, or `flops`, or `tokens` with a model scale), energy in kWh and carbon in gCO2e out, with the confidence the input path earns and the grid intensity used. For inference it adds a modeled water estimate with a low to high range.
|
|
33
|
+
- **`aieds_factors`**: the factor tables the estimate uses: hardware power draw, grid carbon intensity by region, token energy proxies and the J/TFLOP constant.
|
|
34
|
+
- **`aieds_disclose`**: checks a disclosure record against the AiEDs JSON Schema (draft 2020-12) and returns `{ conforms, errors, methodologyBadge }`.
|
|
35
|
+
|
|
36
|
+
AiEDs disclosures are self-attested. `aieds_disclose` checks schema conformance only; it does not re-derive the energy figures.
|
|
37
|
+
|
|
38
|
+
## What this server is not
|
|
39
|
+
|
|
40
|
+
It is not a receipt source. An MCP server never sees the host conversation's token usage, so it cannot print a receipt for a Claude Code, Codex, Grok Build or Copilot CLI response. Those come from the `aieds` command in [@randomknights/aieds](https://www.npmjs.com/package/@randomknights/aieds) and the Random Knights plugin.
|
|
41
|
+
|
|
42
|
+
## Links
|
|
43
|
+
|
|
44
|
+
- Methodology and schema: https://standard.rand0m.ai
|
|
45
|
+
- Source: https://github.com/random-knights/standard/tree/main/mcp
|
|
46
|
+
- Report a vulnerability: https://github.com/random-knights/standard/security
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
The code and the schema are Apache-2.0. The coefficient tables in `spec/v2/aieds-factors.json` are CC BY 4.0. The NOTICE file says which part each license covers.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { HARDWARE_FACTORS, GRID_FACTORS, TOKENS_WH_PER_MILLION, JOULES_PER_TFLOP, DEFAULT_POWER_W, METHODOLOGY_VERSION, } from "./factors.js";
|
|
2
|
+
import { waterFromEnergyKWh } from "./water.js";
|
|
3
|
+
// Deterministic estimate from AiEDs v1 factor tables.
|
|
4
|
+
// Priority: gpuSeconds > flops > tokens. "high" confidence requires direct power measurement
|
|
5
|
+
// (not available in this tool - use "med" for gpuSeconds + known hardware).
|
|
6
|
+
export function estimate(input) {
|
|
7
|
+
const notes = [];
|
|
8
|
+
const { compute, gridRegion = "global_average" } = input;
|
|
9
|
+
const grid = GRID_FACTORS[gridRegion] ?? GRID_FACTORS["global_average"];
|
|
10
|
+
const gCO2ePerKWh = grid.gCO2ePerKWh;
|
|
11
|
+
const effectiveRegion = GRID_FACTORS[gridRegion] ? gridRegion : "global_average";
|
|
12
|
+
if (!GRID_FACTORS[gridRegion]) {
|
|
13
|
+
notes.push(`Grid region '${gridRegion}' not in factor table; using global_average (${gCO2ePerKWh} gCO2e/kWh).`);
|
|
14
|
+
}
|
|
15
|
+
let energyKWh;
|
|
16
|
+
let confidence;
|
|
17
|
+
if (compute.gpuSeconds !== undefined) {
|
|
18
|
+
const hw = compute.hardware ? HARDWARE_FACTORS[compute.hardware] : undefined;
|
|
19
|
+
const powerW = hw?.powerW ?? DEFAULT_POWER_W;
|
|
20
|
+
if (compute.hardware && !hw) {
|
|
21
|
+
notes.push(`Hardware '${compute.hardware}' not in factor table; using ${powerW}W default.`);
|
|
22
|
+
confidence = "low";
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
confidence = hw ? "med" : "low";
|
|
26
|
+
}
|
|
27
|
+
energyKWh = (compute.gpuSeconds * powerW) / 3_600_000;
|
|
28
|
+
}
|
|
29
|
+
else if (compute.flops !== undefined) {
|
|
30
|
+
const joules = (compute.flops / 1e12) * JOULES_PER_TFLOP;
|
|
31
|
+
energyKWh = joules / 3_600_000;
|
|
32
|
+
confidence = "low";
|
|
33
|
+
notes.push(`FLOPs-based estimate uses ${JOULES_PER_TFLOP} J/TFLOP representative factor (FP16/BF16, A100/H100 class).`);
|
|
34
|
+
}
|
|
35
|
+
else if (compute.tokens !== undefined) {
|
|
36
|
+
const scale = compute.modelScale ?? "default";
|
|
37
|
+
const whPerMillion = TOKENS_WH_PER_MILLION[scale] ?? TOKENS_WH_PER_MILLION["default"];
|
|
38
|
+
energyKWh = (compute.tokens / 1_000_000) * whPerMillion / 1000;
|
|
39
|
+
confidence = "low";
|
|
40
|
+
notes.push(`Token proxy uses ${whPerMillion} Wh/1M tokens (${scale} model scale). Provide gpuSeconds + hardware for higher confidence.`);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error("compute must include at least one of: gpuSeconds, flops, tokens.");
|
|
44
|
+
}
|
|
45
|
+
const gCO2e = energyKWh * gCO2ePerKWh;
|
|
46
|
+
const water = input.scope === undefined || input.scope === "inference"
|
|
47
|
+
? waterFromEnergyKWh(energyKWh)
|
|
48
|
+
: null;
|
|
49
|
+
return {
|
|
50
|
+
energyKWh: Math.round(energyKWh * 1_000_000) / 1_000_000,
|
|
51
|
+
gCO2e: Math.round(gCO2e * 100) / 100,
|
|
52
|
+
confidence,
|
|
53
|
+
methodologyVersion: METHODOLOGY_VERSION,
|
|
54
|
+
gridIntensity: { gCO2ePerKWh, region: effectiveRegion },
|
|
55
|
+
notes,
|
|
56
|
+
...(water === null ? {} : { water }),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Loader for the canonical AiEDs factor table.
|
|
2
|
+
//
|
|
3
|
+
// This file used to carry its own transcription of methodology.md Tables 1 to
|
|
4
|
+
// 3. The values were correct, and that was luck rather than design: nothing
|
|
5
|
+
// compared the two, so the only reason they agreed is that neither had been
|
|
6
|
+
// edited since 2026-06-29. Meanwhile METHODOLOGY_VERSION here was bumped to
|
|
7
|
+
// "2.0.0" on 2026-07-12 without the tables moving, so this server has been
|
|
8
|
+
// stamping records "2.0.0" while deriving them by the 1.0.0 method.
|
|
9
|
+
//
|
|
10
|
+
// The version stamp is now read from the table it labels, so the two cannot
|
|
11
|
+
// disagree again. The tables themselves come from spec/v2/aieds-factors.json,
|
|
12
|
+
// which spec/test/factors.test.mjs gates against the ratified document.
|
|
13
|
+
//
|
|
14
|
+
// Methodology 2.0.0 did NOT retire the compute paths. Sections 2.1, 2.2 and
|
|
15
|
+
// 2.3 and Tables 1 to 3 remain normative; 2.4 was added alongside them. These
|
|
16
|
+
// tables are current, not legacy.
|
|
17
|
+
import { readFileSync } from "node:fs";
|
|
18
|
+
const FACTORS_URL = new URL("../../spec/v2/aieds-factors.json", import.meta.url);
|
|
19
|
+
function load() {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(readFileSync(FACTORS_URL, "utf8"));
|
|
22
|
+
}
|
|
23
|
+
catch (cause) {
|
|
24
|
+
throw new Error(`AiEDs factor table not readable at ${FACTORS_URL.pathname}. This server ` +
|
|
25
|
+
`reads spec/v2/aieds-factors.json; it does not carry its own copy of ` +
|
|
26
|
+
`the coefficients.`, { cause });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export const FACTORS = load();
|
|
30
|
+
/**
|
|
31
|
+
* The methodology version these tables belong to, read from the table itself.
|
|
32
|
+
* Never hardcode it here again: a stamp that can disagree with the numbers it
|
|
33
|
+
* labels is worse than no stamp, because it is a false attestation.
|
|
34
|
+
*/
|
|
35
|
+
export const METHODOLOGY_VERSION = FACTORS.methodologyVersion;
|
|
36
|
+
export const IMPACT_MODEL_VERSION = FACTORS.impactModelVersion;
|
|
37
|
+
// Hardware TDP (watts), methodology 2.1 / Table 1. TDP is an upper bound;
|
|
38
|
+
// actual draw at sustained inference is typically 60 to 95 percent of TDP.
|
|
39
|
+
export const HARDWARE_FACTORS = Object.fromEntries(FACTORS.computePaths.hardwareTdp.entries.map((e) => [
|
|
40
|
+
e.id,
|
|
41
|
+
{ powerW: e.powerW, description: e.description, source: e.source },
|
|
42
|
+
]));
|
|
43
|
+
// Grid carbon intensity by region, methodology 3 / Table 3.
|
|
44
|
+
export const GRID_FACTORS = Object.fromEntries(FACTORS.computePaths.gridByRegion.entries.map((e) => [
|
|
45
|
+
e.region,
|
|
46
|
+
{ gCO2ePerKWh: e.gCO2ePerKWh, source: e.source },
|
|
47
|
+
]));
|
|
48
|
+
// Token-to-energy proxy (Wh per million tokens), methodology 2.3 / Table 2.
|
|
49
|
+
// `default` is an ALIAS for the default scale, not a fourth independent value.
|
|
50
|
+
// It used to be a standalone 500 with no counterpart row in Table 2.
|
|
51
|
+
export const TOKENS_WH_PER_MILLION = (() => {
|
|
52
|
+
const byScale = Object.fromEntries(FACTORS.computePaths.tokenProxy.entries.map((e) => [
|
|
53
|
+
e.scale,
|
|
54
|
+
e.whPerMillionTokens,
|
|
55
|
+
]));
|
|
56
|
+
const fallback = byScale[FACTORS.computePaths.tokenProxy.defaultScale];
|
|
57
|
+
if (fallback === undefined) {
|
|
58
|
+
throw new Error(`tokenProxy.defaultScale "${FACTORS.computePaths.tokenProxy.defaultScale}" ` +
|
|
59
|
+
`names no row in Table 2.`);
|
|
60
|
+
}
|
|
61
|
+
return { ...byScale, default: fallback };
|
|
62
|
+
})();
|
|
63
|
+
export const JOULES_PER_TFLOP = FACTORS.computePaths.flop.joulesPerTflop;
|
|
64
|
+
export const DEFAULT_POWER_W = FACTORS.computePaths.hardwareTdp.defaultPowerW;
|
|
65
|
+
export const DEFAULT_GRID_REGION = FACTORS.computePaths.gridByRegion.defaultRegion;
|
|
66
|
+
/**
|
|
67
|
+
* Grid intensity for the section 2.4 response-surface path. Deliberately
|
|
68
|
+
* distinct from GRID_FACTORS.global_average: the two apply to different
|
|
69
|
+
* derivations and methodology 2.4 documents the split. Do not unify them here.
|
|
70
|
+
*/
|
|
71
|
+
export const RESPONSE_SURFACE_GRID_GRAMS_PER_KWH = FACTORS.gridIntensity.responseSurfacePinned.value;
|
|
72
|
+
export const MATURE_REFERENCE_TREE_CO2E_GRAMS_PER_YEAR = FACTORS.constants.matureReferenceTreeCo2eGramsPerYear.value;
|
|
73
|
+
export const MINUTES_PER_YEAR = FACTORS.constants.minutesPerYear.value;
|
|
74
|
+
export const MODEL_ENERGY_PROFILES = FACTORS.responseSurface.profiles;
|
|
75
|
+
export const UNKNOWN_MODEL_PROFILE = FACTORS.responseSurface.unknownProfile;
|
|
76
|
+
/** Profile lookup by model id (case-insensitive prefix match). */
|
|
77
|
+
export function energyProfileForModel(modelId) {
|
|
78
|
+
const id = (modelId ?? "").trim().toLowerCase();
|
|
79
|
+
if (id.length > 0) {
|
|
80
|
+
for (const profile of MODEL_ENERGY_PROFILES) {
|
|
81
|
+
for (const prefix of profile.matchPrefixes) {
|
|
82
|
+
if (id.startsWith(prefix))
|
|
83
|
+
return profile;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return UNKNOWN_MODEL_PROFILE;
|
|
88
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The aieds-mcp command: an MCP server over stdio. Published on npm as
|
|
3
|
+
// @randomknights/aieds-mcp (packages/aieds-mcp); the shebang above is what
|
|
4
|
+
// lets npx and an MCP client run dist/index.js as that command.
|
|
5
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
6
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
7
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
10
|
+
import addFormats from "ajv-formats";
|
|
11
|
+
import { HARDWARE_FACTORS, GRID_FACTORS, TOKENS_WH_PER_MILLION, JOULES_PER_TFLOP, METHODOLOGY_VERSION, } from "./factors.js";
|
|
12
|
+
import { estimate } from "./estimate.js";
|
|
13
|
+
// Load and compile the canonical schema at startup - validates on every aieds_disclose call.
|
|
14
|
+
const schemaPath = new URL("../../spec/aieds.schema.json", import.meta.url);
|
|
15
|
+
const schema = JSON.parse(readFileSync(schemaPath, "utf-8"));
|
|
16
|
+
const ajv = new Ajv2020({ strict: false });
|
|
17
|
+
// ajv-formats v3 is CJS; NodeNext treats the default as module.exports - cast required.
|
|
18
|
+
addFormats(ajv);
|
|
19
|
+
const validateDisclosure = ajv.compile(schema);
|
|
20
|
+
// The server reports the methodology version its factor table declares. The
|
|
21
|
+
// published package carries the same version (scripts/check-npm-packages.mjs
|
|
22
|
+
// holds the two equal), so a client sees one number, not two that can drift.
|
|
23
|
+
const server = new Server({ name: "aieds", version: METHODOLOGY_VERSION }, { capabilities: { tools: {} } });
|
|
24
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
25
|
+
tools: [
|
|
26
|
+
{
|
|
27
|
+
name: "aieds_estimate",
|
|
28
|
+
description: "Estimate energy consumption (kWh) and CO2e emissions (gCO2e) for an AI subject " +
|
|
29
|
+
`from compute metrics. Returns a deterministic result from the AiEDs ${METHODOLOGY_VERSION} factor tables. ` +
|
|
30
|
+
"Confidence reflects the input path: gpuSeconds + known hardware -> 'med'; " +
|
|
31
|
+
"tokens or flops only -> 'low'. Direct power measurement -> 'high' (not emitted by this tool). " +
|
|
32
|
+
"For inference it also returns a modeled water estimate (consumption, a low to high range, " +
|
|
33
|
+
"confidence 'low', US avg grid water) with a one-line plain-words summary.",
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: "object",
|
|
36
|
+
required: ["subject", "compute"],
|
|
37
|
+
properties: {
|
|
38
|
+
subject: {
|
|
39
|
+
type: "object",
|
|
40
|
+
required: ["kind", "name"],
|
|
41
|
+
properties: {
|
|
42
|
+
kind: { type: "string", enum: ["model", "agent", "app"] },
|
|
43
|
+
name: { type: "string" },
|
|
44
|
+
version: { type: "string" },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
compute: {
|
|
48
|
+
type: "object",
|
|
49
|
+
description: "Provide at least one of: gpuSeconds, flops, tokens. gpuSeconds is preferred.",
|
|
50
|
+
properties: {
|
|
51
|
+
gpuSeconds: { type: "number", minimum: 0, description: "Wall-clock GPU-seconds across all accelerators." },
|
|
52
|
+
flops: { type: "number", minimum: 0, description: "Total FLOPs (FP16/BF16 equivalent)." },
|
|
53
|
+
tokens: { type: "number", minimum: 0, description: "Total tokens processed (input + output)." },
|
|
54
|
+
hardware: { type: "string", description: "Hardware key from aieds_factors() hardwareFactors." },
|
|
55
|
+
modelScale: {
|
|
56
|
+
type: "string",
|
|
57
|
+
enum: ["small", "medium", "large"],
|
|
58
|
+
description: "For token-based estimates: model parameter scale (<7B / 7B-70B / >70B).",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
gridRegion: {
|
|
63
|
+
type: "string",
|
|
64
|
+
description: "Grid region key from aieds_factors() gridFactors. Defaults to 'global_average'.",
|
|
65
|
+
},
|
|
66
|
+
scope: {
|
|
67
|
+
type: "string",
|
|
68
|
+
enum: ["device", "usage", "inference", "training"],
|
|
69
|
+
description: "Measurement boundary. Water is returned for 'inference' (the default) only.",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "aieds_factors",
|
|
76
|
+
description: `Return the AiEDs ${METHODOLOGY_VERSION} compute-path factor tables: hardware power draw (W), ` +
|
|
77
|
+
"grid carbon intensities (gCO2e/kWh), token energy proxies (Wh/1M tokens), " +
|
|
78
|
+
"and the J/TFLOP constant. Use these to build disclosures manually or audit estimates.",
|
|
79
|
+
inputSchema: {
|
|
80
|
+
type: "object",
|
|
81
|
+
properties: {},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "aieds_disclose",
|
|
86
|
+
description: "Validate a disclosure object against aieds.schema.json (AiEDs v2 JSON Schema draft 2020-12). " +
|
|
87
|
+
"Returns {conforms, errors, methodologyBadge}. The badge is a short attestation string " +
|
|
88
|
+
`for display or log embedding (e.g. 'AiEDs v${METHODOLOGY_VERSION}, med confidence'). ` +
|
|
89
|
+
"AiEDs disclosures are self-attested - this tool checks schema conformance only.",
|
|
90
|
+
inputSchema: {
|
|
91
|
+
type: "object",
|
|
92
|
+
required: ["disclosure"],
|
|
93
|
+
properties: {
|
|
94
|
+
disclosure: {
|
|
95
|
+
type: "object",
|
|
96
|
+
description: "A disclosure record to validate against aieds.schema.json.",
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
}));
|
|
103
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
104
|
+
const { name, arguments: args } = request.params;
|
|
105
|
+
if (name === "aieds_estimate") {
|
|
106
|
+
const result = estimate(args);
|
|
107
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
108
|
+
}
|
|
109
|
+
if (name === "aieds_factors") {
|
|
110
|
+
const payload = {
|
|
111
|
+
methodologyVersion: METHODOLOGY_VERSION,
|
|
112
|
+
hardwareFactors: HARDWARE_FACTORS,
|
|
113
|
+
gridFactors: GRID_FACTORS,
|
|
114
|
+
tokenWhPerMillion: TOKENS_WH_PER_MILLION,
|
|
115
|
+
joulesPerTflop: JOULES_PER_TFLOP,
|
|
116
|
+
};
|
|
117
|
+
return { content: [{ type: "text", text: JSON.stringify(payload, null, 2) }] };
|
|
118
|
+
}
|
|
119
|
+
if (name === "aieds_disclose") {
|
|
120
|
+
const { disclosure } = args;
|
|
121
|
+
const conforms = validateDisclosure(disclosure);
|
|
122
|
+
const errors = conforms ? [] : (validateDisclosure.errors ?? []);
|
|
123
|
+
const d = disclosure;
|
|
124
|
+
const methodologyBadge = conforms
|
|
125
|
+
? `AiEDs v${d["methodologyVersion"]}, ${d["confidence"]} confidence`
|
|
126
|
+
: null;
|
|
127
|
+
return {
|
|
128
|
+
content: [
|
|
129
|
+
{
|
|
130
|
+
type: "text",
|
|
131
|
+
text: JSON.stringify({ conforms, errors, methodologyBadge }, null, 2),
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
137
|
+
});
|
|
138
|
+
const transport = new StdioServerTransport();
|
|
139
|
+
await server.connect(transport);
|