Skip to content

Commit 7f17118

Browse files
author
flowcore-platform
committed
feat(index): ✨ Add new tools for data core, flow type, and event type management
1 parent 1da1490 commit 7f17118

16 files changed

+445
-40
lines changed

src/index.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@ import { z } from "zod"
99
import pkg from "../package.json"
1010
import { dataCoreResource, eventTypeResource, flowTypeResource, tenantResource } from "./resources"
1111
import {
12+
createDataCoreHandler,
13+
createEventTypeHandler,
14+
createFlowTypeHandler,
15+
getDataCoreHandler,
16+
getEventTypeHandler,
1217
getEventTypeInfoHandler,
1318
getEventsHandler,
19+
getFlowTypeHandler,
1420
getTimeBucketsHandler,
1521
listDataCoresHandler,
1622
listEventTypesHandler,
1723
listFlowTypesHandler,
1824
listTenantsHandler,
25+
requestDeleteDataCoreHandler,
26+
requestDeleteEventTypeHandler,
27+
requestDeleteFlowTypeHandler,
28+
requestTruncateEventTypeHandler,
1929
} from "./tools"
2030

2131
const OIDC_ISSUER = "https://auth.flowcore.io/realms/flowcore/.well-known/openid-configuration"
@@ -63,6 +73,19 @@ const server = new McpServer({
6373
prompts: [],
6474
})
6575

76+
// Read tools
77+
server.tool("get_data_core", "Get a data core", {
78+
dataCoreId: z.string().describe("The data core ID to get"),
79+
}, getDataCoreHandler(flowcoreClient))
80+
81+
server.tool("get_flow_type", "Get a flow type", {
82+
flowTypeId: z.string().describe("The flow type ID to get"),
83+
}, getFlowTypeHandler(flowcoreClient))
84+
85+
server.tool("get_event_type", "Get an event type", {
86+
eventTypeId: z.string().describe("The event type ID to get"),
87+
}, getEventTypeHandler(flowcoreClient))
88+
6689
server.tool("list_tenants", "List all tenants I have access to", listTenantsHandler(flowcoreClient))
6790
server.tool(
6891
"list_data_cores",
@@ -138,6 +161,83 @@ server.tool(
138161
getTimeBucketsHandler(flowcoreClient),
139162
)
140163

164+
// Write tools
165+
server.tool(
166+
"create_data_core",
167+
"Create a data core in a tenant",
168+
{
169+
tenantId: z.string().describe("The tenant ID to create the data core for"),
170+
name: z.string().describe("The name of the data core"),
171+
description: z.string().describe("The description of the data core"),
172+
accessControl: z.enum(["public", "private"]).describe("The access control of the data core"),
173+
deleteProtection: z.boolean().describe("Whether the data core is delete protected"),
174+
},
175+
createDataCoreHandler(flowcoreClient),
176+
)
177+
178+
server.tool(
179+
"create_flow_type",
180+
"Create a flow type in a data core",
181+
{
182+
dataCoreId: z.string().describe("The id of the data core"),
183+
name: z.string().describe("The name of the flow type"),
184+
description: z.string().describe("The description of the flow type"),
185+
},
186+
createFlowTypeHandler(flowcoreClient),
187+
)
188+
189+
server.tool(
190+
"create_event_type",
191+
"Create an event type in a flow type",
192+
{
193+
flowTypeId: z.string().describe("The id of the flow type"),
194+
name: z.string().describe("The name of the event type"),
195+
description: z.string().describe("The description of the event type"),
196+
},
197+
createEventTypeHandler(flowcoreClient),
198+
)
199+
200+
server.tool(
201+
"request_delete_event_type",
202+
"Request to delete an event type, this will delete all events in the event type, this is irreversible. If wait for delete is true the tool will wait up to 25 seconds for the event type to be deleted, if not it will return immediately, you have to use the get_event_type tool to check if the event type is deleted.",
203+
{
204+
eventTypeId: z.string().describe("The id of the event type"),
205+
waitForDelete: z.boolean().optional().describe("Wait for the event type to be deleted (default: false)"),
206+
},
207+
requestDeleteEventTypeHandler(flowcoreClient),
208+
)
209+
210+
server.tool(
211+
"request_truncate_event_type",
212+
"Request to truncate an event type, this will delete all events in the event type, this is irreversible. If wait for truncate is true the tool will wait up to 25 seconds for the event type to be truncated, if not it will return immediately, you have to use the get_event_type tool to check if the event type is truncated.",
213+
{
214+
eventTypeId: z.string().describe("The id of the event type"),
215+
waitForTruncate: z.boolean().optional().describe("Wait for the event type to be truncated (default: false)"),
216+
},
217+
requestTruncateEventTypeHandler(flowcoreClient),
218+
)
219+
220+
server.tool(
221+
"request_delete_flow_type",
222+
"Request to delete a flow type, this will delete all events in the flow type, this is irreversible. If wait for delete is true the tool will wait up to 25 seconds for the flow type to be deleted, if not it will return immediately, you have to use the get_flow_type tool to check if the flow type is deleted.",
223+
{
224+
flowTypeId: z.string().describe("The id of the flow type"),
225+
waitForDelete: z.boolean().optional().describe("Wait for the flow type to be deleted (default: false)"),
226+
},
227+
requestDeleteFlowTypeHandler(flowcoreClient),
228+
)
229+
230+
server.tool(
231+
"request_delete_data_core",
232+
"Request to delete a data core, this will delete all events in the data core, this is irreversible. If wait for delete is true the tool will wait up to 25 seconds for the data core to be deleted, if not it will return immediately, you have to use the get_data_core tool to check if the data core is deleted.",
233+
{
234+
dataCoreId: z.string().describe("The id of the data core"),
235+
waitForDelete: z.boolean().optional().describe("Wait for the data core to be deleted (default: false)"),
236+
},
237+
requestDeleteDataCoreHandler(flowcoreClient),
238+
)
239+
240+
// Read resources
141241
server.resource(
142242
"tenant",
143243
new ResourceTemplate("tenant://{tenantId}", { list: undefined }),

src/tools/create-data-core.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { DataCoreCreateCommand, type DataCoreCreateInput, type FlowcoreClient } from "@flowcore/sdk"
2+
3+
export const createDataCoreHandler = (flowcoreClient: FlowcoreClient) => async (input: DataCoreCreateInput) => {
4+
try {
5+
const result = await flowcoreClient.execute(new DataCoreCreateCommand(input))
6+
7+
return {
8+
content: [
9+
{
10+
type: "text" as const,
11+
text: JSON.stringify(result),
12+
},
13+
],
14+
}
15+
} catch (error) {
16+
// Create properly typed content array for error
17+
const content = [
18+
{
19+
type: "text" as const,
20+
text: JSON.stringify(`Failed to create data core with error: ${error}`),
21+
},
22+
]
23+
24+
return { isError: true, content }
25+
}
26+
}

src/tools/create-event-type.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { EventTypeCreateCommand, type EventTypeCreateInput, type FlowcoreClient } from "@flowcore/sdk"
2+
3+
export const createEventTypeHandler = (flowcoreClient: FlowcoreClient) => async (input: EventTypeCreateInput) => {
4+
try {
5+
const result = await flowcoreClient.execute(new EventTypeCreateCommand(input))
6+
7+
return {
8+
content: [
9+
{
10+
type: "text" as const,
11+
text: JSON.stringify(result),
12+
},
13+
],
14+
}
15+
} catch (error) {
16+
// Create properly typed content array for error
17+
const content = [
18+
{
19+
type: "text" as const,
20+
text: JSON.stringify(`Failed to create event type with error: ${error}`),
21+
},
22+
]
23+
24+
return { isError: true, content }
25+
}
26+
}

src/tools/create-flow-type.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { FlowTypeCreateCommand, type FlowTypeCreateInput, type FlowcoreClient } from "@flowcore/sdk"
2+
3+
export const createFlowTypeHandler = (flowcoreClient: FlowcoreClient) => async (input: FlowTypeCreateInput) => {
4+
try {
5+
const result = await flowcoreClient.execute(new FlowTypeCreateCommand(input))
6+
7+
return {
8+
content: [
9+
{
10+
type: "text" as const,
11+
text: JSON.stringify(result),
12+
},
13+
],
14+
}
15+
} catch (error) {
16+
// Create properly typed content array for error
17+
const content = [
18+
{
19+
type: "text" as const,
20+
text: JSON.stringify(`Failed to create flow type with error: ${error}`),
21+
},
22+
]
23+
24+
return { isError: true, content }
25+
}
26+
}

src/tools/get-data-core.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { DataCoreFetchCommand, type FlowcoreClient } from "@flowcore/sdk";
2+
3+
export const getDataCoreHandler =
4+
(flowcoreClient: FlowcoreClient) =>
5+
async ({ dataCoreId }: { dataCoreId: string }) => {
6+
try {
7+
const result = await flowcoreClient.execute(
8+
new DataCoreFetchCommand({ dataCoreId }),
9+
);
10+
11+
return {
12+
content: [
13+
{
14+
type: "text" as const,
15+
text: JSON.stringify(result),
16+
},
17+
],
18+
};
19+
} catch (error) {
20+
// Create properly typed content array for error
21+
const content = [
22+
{
23+
type: "text" as const,
24+
text: JSON.stringify(
25+
`Failed to get data core with error: ${error}`,
26+
),
27+
},
28+
];
29+
30+
return { isError: true, content };
31+
}
32+
};

src/tools/get-event-type.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { EventTypeFetchCommand, type FlowcoreClient } from "@flowcore/sdk";
2+
3+
export const getEventTypeHandler =
4+
(flowcoreClient: FlowcoreClient) =>
5+
async ({ eventTypeId }: { eventTypeId: string }) => {
6+
try {
7+
const result = await flowcoreClient.execute(
8+
new EventTypeFetchCommand({ eventTypeId }),
9+
);
10+
11+
return {
12+
content: [
13+
{
14+
type: "text" as const,
15+
text: JSON.stringify(result),
16+
},
17+
],
18+
};
19+
} catch (error) {
20+
// Create properly typed content array for error
21+
const content = [
22+
{
23+
type: "text" as const,
24+
text: JSON.stringify(
25+
`Failed to get event type with error: ${error}`,
26+
),
27+
},
28+
];
29+
30+
return { isError: true, content };
31+
}
32+
};

src/tools/get-flow-type.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { FlowTypeFetchCommand, type FlowcoreClient } from "@flowcore/sdk";
2+
3+
export const getFlowTypeHandler =
4+
(flowcoreClient: FlowcoreClient) =>
5+
async ({ flowTypeId }: { flowTypeId: string }) => {
6+
try {
7+
const result = await flowcoreClient.execute(
8+
new FlowTypeFetchCommand({ flowTypeId }),
9+
);
10+
11+
return {
12+
content: [
13+
{
14+
type: "text" as const,
15+
text: JSON.stringify(result),
16+
},
17+
],
18+
};
19+
} catch (error) {
20+
// Create properly typed content array for error
21+
const content = [
22+
{
23+
type: "text" as const,
24+
text: JSON.stringify(
25+
`Failed to get flow type with error: ${error}`,
26+
),
27+
},
28+
];
29+
30+
return { isError: true, content };
31+
}
32+
};

src/tools/index.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
export * from "./get-event-type-info";
2-
export * from "./get-events";
3-
export * from "./list-data-cores";
4-
export * from "./list-event-types";
5-
export * from "./list-flow-types";
6-
export * from "./list-tenants";
7-
export * from "./get-time-buckets";
1+
export * from "./create-data-core"
2+
export * from "./create-event-type"
3+
export * from "./create-flow-type"
4+
export * from "./get-data-core"
5+
export * from "./get-event-type"
6+
export * from "./get-event-type-info"
7+
export * from "./get-events"
8+
export * from "./get-flow-type"
9+
export * from "./get-time-buckets"
10+
export * from "./list-data-cores"
11+
export * from "./list-event-types"
12+
export * from "./list-flow-types"
13+
export * from "./list-tenants"
14+
export * from "./request-delete-data-core"
15+
export * from "./request-delete-event-type"
16+
export * from "./request-delete-flow-type"
17+
export * from "./request-truncate-event-type"

0 commit comments

Comments
 (0)