duoops 0.2.13 → 0.2.15
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/mcp-server/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {authMiddleware, oauthEndpoints} from './auth.js'
|
|
|
7
7
|
import {registerEmissionsTools} from './tools/emissions.js'
|
|
8
8
|
import {registerProfileTools} from './tools/profiles.js'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
function createServer(): McpServer {
|
|
11
11
|
const server = new McpServer({
|
|
12
12
|
name: 'duoops-carbon',
|
|
13
13
|
version: '1.0.0',
|
|
@@ -15,7 +15,10 @@ async function main() {
|
|
|
15
15
|
|
|
16
16
|
registerEmissionsTools(server)
|
|
17
17
|
registerProfileTools(server)
|
|
18
|
+
return server
|
|
19
|
+
}
|
|
18
20
|
|
|
21
|
+
async function main() {
|
|
19
22
|
const app = express()
|
|
20
23
|
|
|
21
24
|
app.get('/health', (_req, res) => {
|
|
@@ -24,11 +27,12 @@ async function main() {
|
|
|
24
27
|
|
|
25
28
|
oauthEndpoints(app)
|
|
26
29
|
|
|
30
|
+
const sseServer = createServer()
|
|
27
31
|
let sseTransport: SSEServerTransport
|
|
28
32
|
|
|
29
33
|
app.get('/sse', authMiddleware, async (req, res) => {
|
|
30
34
|
sseTransport = new SSEServerTransport('/message', res)
|
|
31
|
-
await
|
|
35
|
+
await sseServer.connect(sseTransport)
|
|
32
36
|
})
|
|
33
37
|
|
|
34
38
|
app.post('/message', authMiddleware, async (req, res) => {
|
|
@@ -42,24 +46,18 @@ async function main() {
|
|
|
42
46
|
|
|
43
47
|
app.post('/mcp', authMiddleware, async (req, res) => {
|
|
44
48
|
const transport = new StreamableHTTPServerTransport({sessionIdGenerator: undefined})
|
|
45
|
-
|
|
46
|
-
transport.close()
|
|
47
|
-
})
|
|
49
|
+
const server = createServer()
|
|
48
50
|
await server.connect(transport)
|
|
49
51
|
await transport.handleRequest(req, res)
|
|
52
|
+
await server.close()
|
|
50
53
|
})
|
|
51
54
|
|
|
52
55
|
app.get('/mcp', authMiddleware, async (req, res) => {
|
|
53
|
-
|
|
54
|
-
res.on('close', () => {
|
|
55
|
-
transport.close()
|
|
56
|
-
})
|
|
57
|
-
await server.connect(transport)
|
|
58
|
-
await transport.handleRequest(req, res)
|
|
56
|
+
res.writeHead(405).end(JSON.stringify({error: 'Method not allowed', jsonrpc: '2.0'}))
|
|
59
57
|
})
|
|
60
58
|
|
|
61
59
|
app.delete('/mcp', async (_req, res) => {
|
|
62
|
-
res.
|
|
60
|
+
res.writeHead(405).end(JSON.stringify({error: 'Method not allowed', jsonrpc: '2.0'}))
|
|
63
61
|
})
|
|
64
62
|
|
|
65
63
|
const port = process.env.PORT || 8080
|
|
@@ -59,7 +59,10 @@ Total recent: ${totalEmissions.toFixed(3)} gCO2e
|
|
|
59
59
|
Total energy: ${totalEnergy.toFixed(4)} kWh
|
|
60
60
|
|
|
61
61
|
Recent Jobs:
|
|
62
|
-
${records.map(r =>
|
|
62
|
+
${records.map(r => {
|
|
63
|
+
const ts = typeof r.ingested_at === 'object' && r.ingested_at !== null ? (r.ingested_at as {value: string}).value : String(r.ingested_at)
|
|
64
|
+
return `- ${ts} | ${r.gitlab_job_name} (${r.machine_type}): ${r.total_emissions_g.toFixed(3)} gCO2e, ${r.energy_kwh.toFixed(4)} kWh, ${r.runtime_seconds.toFixed(0)}s`
|
|
65
|
+
}).join('\n')}
|
|
63
66
|
`
|
|
64
67
|
|
|
65
68
|
return {
|
package/oclif.manifest.json
CHANGED