@pantheon.ai/mcp 0.0.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/.idea/compiler.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/pantheon-mcp.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/package.json +29 -0
- package/packages/sdk/package.json +16 -0
- package/packages/sdk/src/api/auth.ts +22 -0
- package/packages/sdk/src/api/connectors.ts +27 -0
- package/packages/sdk/src/api/environments.ts +53 -0
- package/packages/sdk/src/api/projects.ts +143 -0
- package/packages/sdk/src/api/stream-proxy.ts +17 -0
- package/packages/sdk/src/index.ts +16 -0
- package/packages/sdk/src/lib/api-executor.ts +169 -0
- package/packages/sdk/src/lib/api.ts +265 -0
- package/packages/sdk/src/lib/stream-parser.ts +30 -0
- package/packages/sdk/src/lib/validator.ts +19 -0
- package/packages/sdk/src/lib/vercel-ai-hack.ts +133 -0
- package/packages/sdk/src/lib/zod.ts +32 -0
- package/packages/sdk/src/schemas/ai.ts +473 -0
- package/packages/sdk/src/schemas/branch.ts +99 -0
- package/packages/sdk/src/schemas/common.ts +19 -0
- package/packages/sdk/src/schemas/environments.ts +19 -0
- package/packages/sdk/src/schemas/exploration.ts +54 -0
- package/packages/sdk/src/schemas/fs.ts +38 -0
- package/packages/sdk/src/schemas/project.ts +208 -0
- package/packages/sdk/tsconfig.json +17 -0
- package/patches/ai+6.0.45.patch +163 -0
- package/src/index.ts +34 -0
- package/src/mcp/mcp.ts +172 -0
- package/src/stdio.ts +11 -0
- package/src/streamableHttp.ts +60 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { StreamResponseParser } from "@pantheon/sdk/lib/stream-parser"
|
|
2
|
+
import { zodJsonDate, ZodStream } from "@pantheon/sdk/lib/zod"
|
|
3
|
+
import {
|
|
4
|
+
type MasterAgentMessage,
|
|
5
|
+
type MasterAgentMessageChunk,
|
|
6
|
+
type MasterAgentMessagePart,
|
|
7
|
+
messageMetadataSchema,
|
|
8
|
+
} from "@pantheon/sdk/schemas/ai"
|
|
9
|
+
import { z, type ZodType } from "zod"
|
|
10
|
+
|
|
11
|
+
export type Project = {
|
|
12
|
+
id: string
|
|
13
|
+
name: string
|
|
14
|
+
display_name: string
|
|
15
|
+
category: string
|
|
16
|
+
description: string
|
|
17
|
+
user_id: string
|
|
18
|
+
root_branch_id: string | null
|
|
19
|
+
ongoing_stream_id: string | null
|
|
20
|
+
status?:
|
|
21
|
+
| "CREATED"
|
|
22
|
+
| "PROVISIONING"
|
|
23
|
+
| "READY"
|
|
24
|
+
| "RUNNING"
|
|
25
|
+
| "PAUSED"
|
|
26
|
+
| "FAILED"
|
|
27
|
+
| "ARCHIVED"
|
|
28
|
+
| null
|
|
29
|
+
error_message?: string | null
|
|
30
|
+
created_at: Date
|
|
31
|
+
updated_at: Date
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const projectSchema = z.object({
|
|
35
|
+
id: z.string(),
|
|
36
|
+
name: z.string(),
|
|
37
|
+
display_name: z.string(),
|
|
38
|
+
category: z.string(),
|
|
39
|
+
description: z.string(),
|
|
40
|
+
user_id: z.string(),
|
|
41
|
+
root_branch_id: z.string().nullable(),
|
|
42
|
+
ongoing_stream_id: z.string().nullable(),
|
|
43
|
+
status: z
|
|
44
|
+
.enum([
|
|
45
|
+
"CREATED",
|
|
46
|
+
"PROVISIONING",
|
|
47
|
+
"READY",
|
|
48
|
+
"RUNNING",
|
|
49
|
+
"PAUSED",
|
|
50
|
+
"FAILED",
|
|
51
|
+
"ARCHIVED",
|
|
52
|
+
])
|
|
53
|
+
.nullable()
|
|
54
|
+
.optional(),
|
|
55
|
+
error_message: z.string().nullable().optional(),
|
|
56
|
+
created_at: zodJsonDate,
|
|
57
|
+
updated_at: zodJsonDate,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
export interface ProjectMessage extends MasterAgentMessage {
|
|
61
|
+
ordinal: number
|
|
62
|
+
project_id: string
|
|
63
|
+
event_stream_id: string | null
|
|
64
|
+
source_request_id?: string | null
|
|
65
|
+
status: string | null
|
|
66
|
+
is_finished: boolean
|
|
67
|
+
created_at: Date
|
|
68
|
+
updated_at: Date
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ProjectQueuedRequest {
|
|
72
|
+
id: string
|
|
73
|
+
type: string
|
|
74
|
+
payload: unknown
|
|
75
|
+
requested_at: Date
|
|
76
|
+
summary: string
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const projectMessageSchema = z.object({
|
|
80
|
+
id: z.string(),
|
|
81
|
+
role: z.enum(["system", "user", "assistant"]),
|
|
82
|
+
metadata: messageMetadataSchema.nullable().optional(),
|
|
83
|
+
parts: z.array(
|
|
84
|
+
z.object().loose() as unknown as ZodType<MasterAgentMessagePart>
|
|
85
|
+
),
|
|
86
|
+
ordinal: z.number(),
|
|
87
|
+
project_id: z.string(),
|
|
88
|
+
source_request_id: z.string().nullable().optional(),
|
|
89
|
+
event_stream_id: z.string().nullable(),
|
|
90
|
+
status: z.string().nullable(),
|
|
91
|
+
is_finished: z.boolean(),
|
|
92
|
+
created_at: zodJsonDate,
|
|
93
|
+
updated_at: zodJsonDate,
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const projectMessageStreamParser = new StreamResponseParser({
|
|
97
|
+
pipe: (input) => {
|
|
98
|
+
return input
|
|
99
|
+
.pipeThrough(new TextDecoderStream())
|
|
100
|
+
.pipeThrough(new BufferedLinesStream("\n\n"))
|
|
101
|
+
.pipeThrough(new SSEDataDecoderStream())
|
|
102
|
+
.pipeThrough(
|
|
103
|
+
new ZodStream({
|
|
104
|
+
schema: z
|
|
105
|
+
.object()
|
|
106
|
+
.loose() as unknown as ZodType<MasterAgentMessageChunk>,
|
|
107
|
+
})
|
|
108
|
+
)
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const projectRawMessageStreamParser = new StreamResponseParser({
|
|
113
|
+
pipe: (input) => {
|
|
114
|
+
return input
|
|
115
|
+
.pipeThrough(new TextDecoderStream())
|
|
116
|
+
.pipeThrough(new BufferedLinesStream("\n\n"))
|
|
117
|
+
.pipeThrough(new SSEDataDecoderStream())
|
|
118
|
+
.pipeThrough(
|
|
119
|
+
new ZodStream({
|
|
120
|
+
schema: z.object().loose() as unknown as ZodType<unknown>,
|
|
121
|
+
})
|
|
122
|
+
)
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
export const projectQueuedRequestSchema = z.object({
|
|
127
|
+
id: z.string(),
|
|
128
|
+
type: z.string(),
|
|
129
|
+
payload: z.unknown(),
|
|
130
|
+
requested_at: zodJsonDate,
|
|
131
|
+
summary: z.string(),
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
export const projectBackgroundTaskSchema = z.object({
|
|
135
|
+
task_id: z.string(),
|
|
136
|
+
name: z.string().nullable(),
|
|
137
|
+
action_type: z.enum(["execution", "exploration"]),
|
|
138
|
+
action_id: z.string(),
|
|
139
|
+
status: z.enum(["SUCCESS", "FAILURE", "PENDING", "STARTED"]).nullable(),
|
|
140
|
+
result: z.object().loose().nullable(),
|
|
141
|
+
retries: z.number().nullable(),
|
|
142
|
+
started_at: zodJsonDate.nullable(),
|
|
143
|
+
last_polled_at: zodJsonDate.nullable(),
|
|
144
|
+
ended_at: zodJsonDate.nullable(),
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
class BufferedLinesStream extends TransformStream<string, string> {
|
|
148
|
+
constructor(sep = "\n") {
|
|
149
|
+
let buffer = ""
|
|
150
|
+
super({
|
|
151
|
+
transform(chunk, controller) {
|
|
152
|
+
chunk = buffer += chunk
|
|
153
|
+
|
|
154
|
+
while (true) {
|
|
155
|
+
const index = chunk.indexOf(sep)
|
|
156
|
+
if (index === -1) {
|
|
157
|
+
buffer = chunk
|
|
158
|
+
break
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const line = chunk.slice(0, index).trim()
|
|
162
|
+
if (line) {
|
|
163
|
+
controller.enqueue(line)
|
|
164
|
+
}
|
|
165
|
+
chunk = chunk.slice(index + sep.length)
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
flush() {
|
|
170
|
+
if (buffer) {
|
|
171
|
+
console.warn("buffered lines stream has unprocessed lines:", buffer)
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export class SSEDataDecoderStream extends TransformStream<string, any> {
|
|
179
|
+
constructor() {
|
|
180
|
+
let handle: ReturnType<typeof setTimeout> | undefined = undefined
|
|
181
|
+
|
|
182
|
+
super({
|
|
183
|
+
transform: (chunk, controller) => {
|
|
184
|
+
clearTimeout(handle)
|
|
185
|
+
handle = setTimeout(() => {
|
|
186
|
+
controller.error(new Error("Read timeout, please retry."))
|
|
187
|
+
}, 15000)
|
|
188
|
+
|
|
189
|
+
if (/^data:/.test(chunk)) {
|
|
190
|
+
const part = chunk.replace(/^data: /, "").trim()
|
|
191
|
+
if (part === "[DONE]") {
|
|
192
|
+
} else {
|
|
193
|
+
try {
|
|
194
|
+
controller.enqueue(JSON.parse(part))
|
|
195
|
+
} catch (e) {
|
|
196
|
+
console.error("invalid sse chunk", chunk, e)
|
|
197
|
+
controller.error(e)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
console.debug("ignore sse comment", chunk)
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { projectMessageStreamParser, projectRawMessageStreamParser }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["ESNext", "DOM", "DOM.AsyncIterable"],
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"strict": true,
|
|
6
|
+
"module": "NodeNext",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipDefaultLibCheck": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"baseUrl": ".",
|
|
12
|
+
"paths": {
|
|
13
|
+
"@pantheon/sdk/*": ["./src/*"]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"include": ["src"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
diff --git a/node_modules/ai/dist/index.d.mts b/node_modules/ai/dist/index.d.mts
|
|
2
|
+
index f66d872..74d7d44 100644
|
|
3
|
+
--- a/node_modules/ai/dist/index.d.mts
|
|
4
|
+
+++ b/node_modules/ai/dist/index.d.mts
|
|
5
|
+
@@ -5633,3 +5633,55 @@ declare global {
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
|
|
9
|
+
+
|
|
10
|
+
+
|
|
11
|
+
+export type StreamingUIMessageState<UI_MESSAGE extends UIMessage> = {
|
|
12
|
+
+ message: UI_MESSAGE;
|
|
13
|
+
+ activeTextParts: Record<string, TextUIPart>;
|
|
14
|
+
+ activeReasoningParts: Record<string, ReasoningUIPart>;
|
|
15
|
+
+ partialToolCalls: Record<
|
|
16
|
+
+ string,
|
|
17
|
+
+ {
|
|
18
|
+
+ text: string;
|
|
19
|
+
+ index: number;
|
|
20
|
+
+ toolName: string;
|
|
21
|
+
+ dynamic?: boolean;
|
|
22
|
+
+ title?: string;
|
|
23
|
+
+ }
|
|
24
|
+
+ >;
|
|
25
|
+
+ finishReason?: FinishReason;
|
|
26
|
+
+};
|
|
27
|
+
+
|
|
28
|
+
+export function createStreamingUIMessageState<UI_MESSAGE extends UIMessage>({
|
|
29
|
+
+ lastMessage,
|
|
30
|
+
+ messageId,
|
|
31
|
+
+}: {
|
|
32
|
+
+ lastMessage: UI_MESSAGE | undefined;
|
|
33
|
+
+ messageId: string;
|
|
34
|
+
+}): StreamingUIMessageState<UI_MESSAGE>
|
|
35
|
+
+
|
|
36
|
+
+export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
37
|
+
+ stream,
|
|
38
|
+
+ messageMetadataSchema,
|
|
39
|
+
+ dataPartSchemas,
|
|
40
|
+
+ runUpdateMessageJob,
|
|
41
|
+
+ onError,
|
|
42
|
+
+ onToolCall,
|
|
43
|
+
+ onData,
|
|
44
|
+
+}: {
|
|
45
|
+
+ // input stream is not fully typed yet:
|
|
46
|
+
+ stream: ReadableStream<UIMessageChunk>;
|
|
47
|
+
+ messageMetadataSchema?: FlexibleSchema<InferUIMessageMetadata<UI_MESSAGE>>;
|
|
48
|
+
+ dataPartSchemas?: UIDataTypesToSchemas<InferUIMessageData<UI_MESSAGE>>;
|
|
49
|
+
+ onToolCall?: (options: {
|
|
50
|
+
+ toolCall: InferUIMessageToolCall<UI_MESSAGE>;
|
|
51
|
+
+ }) => void | PromiseLike<void>;
|
|
52
|
+
+ onData?: (dataPart: DataUIPart<InferUIMessageData<UI_MESSAGE>>) => void;
|
|
53
|
+
+ runUpdateMessageJob: (
|
|
54
|
+
+ job: (options: {
|
|
55
|
+
+ state: StreamingUIMessageState<UI_MESSAGE>;
|
|
56
|
+
+ write: () => void;
|
|
57
|
+
+ }) => Promise<void>,
|
|
58
|
+
+ ) => Promise<void>;
|
|
59
|
+
+ onError: ErrorHandler;
|
|
60
|
+
+}): ReadableStream<InferUIMessageChunk<UI_MESSAGE>>
|
|
61
|
+
diff --git a/node_modules/ai/dist/index.d.ts b/node_modules/ai/dist/index.d.ts
|
|
62
|
+
index f66d872..fdce962 100644
|
|
63
|
+
--- a/node_modules/ai/dist/index.d.ts
|
|
64
|
+
+++ b/node_modules/ai/dist/index.d.ts
|
|
65
|
+
@@ -5633,3 +5633,54 @@ declare global {
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
|
|
69
|
+
+
|
|
70
|
+
+export type StreamingUIMessageState<UI_MESSAGE extends UIMessage> = {
|
|
71
|
+
+ message: UI_MESSAGE;
|
|
72
|
+
+ activeTextParts: Record<string, TextUIPart>;
|
|
73
|
+
+ activeReasoningParts: Record<string, ReasoningUIPart>;
|
|
74
|
+
+ partialToolCalls: Record<
|
|
75
|
+
+ string,
|
|
76
|
+
+ {
|
|
77
|
+
+ text: string;
|
|
78
|
+
+ index: number;
|
|
79
|
+
+ toolName: string;
|
|
80
|
+
+ dynamic?: boolean;
|
|
81
|
+
+ title?: string;
|
|
82
|
+
+ }
|
|
83
|
+
+ >;
|
|
84
|
+
+ finishReason?: FinishReason;
|
|
85
|
+
+};
|
|
86
|
+
+
|
|
87
|
+
+export function createStreamingUIMessageState<UI_MESSAGE extends UIMessage>({
|
|
88
|
+
+ lastMessage,
|
|
89
|
+
+ messageId,
|
|
90
|
+
+}: {
|
|
91
|
+
+ lastMessage: UI_MESSAGE | undefined;
|
|
92
|
+
+ messageId: string;
|
|
93
|
+
+}): StreamingUIMessageState<UI_MESSAGE>
|
|
94
|
+
+
|
|
95
|
+
+export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
96
|
+
+ stream,
|
|
97
|
+
+ messageMetadataSchema,
|
|
98
|
+
+ dataPartSchemas,
|
|
99
|
+
+ runUpdateMessageJob,
|
|
100
|
+
+ onError,
|
|
101
|
+
+ onToolCall,
|
|
102
|
+
+ onData,
|
|
103
|
+
+}: {
|
|
104
|
+
+ // input stream is not fully typed yet:
|
|
105
|
+
+ stream: ReadableStream<UIMessageChunk>;
|
|
106
|
+
+ messageMetadataSchema?: FlexibleSchema<InferUIMessageMetadata<UI_MESSAGE>>;
|
|
107
|
+
+ dataPartSchemas?: UIDataTypesToSchemas<InferUIMessageData<UI_MESSAGE>>;
|
|
108
|
+
+ onToolCall?: (options: {
|
|
109
|
+
+ toolCall: InferUIMessageToolCall<UI_MESSAGE>;
|
|
110
|
+
+ }) => void | PromiseLike<void>;
|
|
111
|
+
+ onData?: (dataPart: DataUIPart<InferUIMessageData<UI_MESSAGE>>) => void;
|
|
112
|
+
+ runUpdateMessageJob: (
|
|
113
|
+
+ job: (options: {
|
|
114
|
+
+ state: StreamingUIMessageState<UI_MESSAGE>;
|
|
115
|
+
+ write: () => void;
|
|
116
|
+
+ }) => Promise<void>,
|
|
117
|
+
+ ) => Promise<void>;
|
|
118
|
+
+ onError: ErrorHandler;
|
|
119
|
+
+}): ReadableStream<InferUIMessageChunk<UI_MESSAGE>>
|
|
120
|
+
diff --git a/node_modules/ai/dist/index.js b/node_modules/ai/dist/index.js
|
|
121
|
+
index 114687a..8b65974 100644
|
|
122
|
+
--- a/node_modules/ai/dist/index.js
|
|
123
|
+
+++ b/node_modules/ai/dist/index.js
|
|
124
|
+
@@ -4889,7 +4889,7 @@ function getToolName(part) {
|
|
125
|
+
var getToolOrDynamicToolName = getToolName;
|
|
126
|
+
|
|
127
|
+
// src/ui/process-ui-message-stream.ts
|
|
128
|
+
-function createStreamingUIMessageState({
|
|
129
|
+
+export function createStreamingUIMessageState({
|
|
130
|
+
lastMessage,
|
|
131
|
+
messageId
|
|
132
|
+
}) {
|
|
133
|
+
@@ -4905,7 +4905,7 @@ function createStreamingUIMessageState({
|
|
134
|
+
partialToolCalls: {}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
-function processUIMessageStream({
|
|
138
|
+
+export function processUIMessageStream({
|
|
139
|
+
stream,
|
|
140
|
+
messageMetadataSchema,
|
|
141
|
+
dataPartSchemas,
|
|
142
|
+
diff --git a/node_modules/ai/dist/index.mjs b/node_modules/ai/dist/index.mjs
|
|
143
|
+
index e5278cb..f74b520 100644
|
|
144
|
+
--- a/node_modules/ai/dist/index.mjs
|
|
145
|
+
+++ b/node_modules/ai/dist/index.mjs
|
|
146
|
+
@@ -4812,7 +4812,7 @@ function getToolName(part) {
|
|
147
|
+
var getToolOrDynamicToolName = getToolName;
|
|
148
|
+
|
|
149
|
+
// src/ui/process-ui-message-stream.ts
|
|
150
|
+
-function createStreamingUIMessageState({
|
|
151
|
+
+export function createStreamingUIMessageState({
|
|
152
|
+
lastMessage,
|
|
153
|
+
messageId
|
|
154
|
+
}) {
|
|
155
|
+
@@ -4828,7 +4828,7 @@ function createStreamingUIMessageState({
|
|
156
|
+
partialToolCalls: {}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
-function processUIMessageStream({
|
|
160
|
+
+export function processUIMessageStream({
|
|
161
|
+
stream,
|
|
162
|
+
messageMetadataSchema,
|
|
163
|
+
dataPartSchemas,
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { startStdio } from './stdio.ts';
|
|
4
|
+
import { startStreamableHttpServer } from './streamableHttp.ts';
|
|
5
|
+
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
|
|
8
|
+
function printHelp (message?: string) {
|
|
9
|
+
console.error(`${message || 'Usage'}
|
|
10
|
+
npx @pantheon.ai/mcp stdio <Api-Key>
|
|
11
|
+
PORT=10086 npx @pantheon.ai/mcp http [Optional Api-Key]
|
|
12
|
+
`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (args.includes('--help')) {
|
|
16
|
+
printHelp();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
switch (args[0]) {
|
|
20
|
+
case 'stdio':
|
|
21
|
+
if (!args[1]) {
|
|
22
|
+
printHelp('Api-Key is required for stdio mode');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
await startStdio({ apiKey: args[1] });
|
|
26
|
+
break;
|
|
27
|
+
case 'http':
|
|
28
|
+
if (!args[1]) console.error('API Key not provided, client connections must provide authentication header.');
|
|
29
|
+
await startStreamableHttpServer({ apiKey: args[1] });
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
printHelp();
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
package/src/mcp/mcp.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { getErrorMessage } from '@ai-sdk/provider';
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { type Api, createProject, createProjectExploration, getProject, getProjectBranch, getProjectBranchOutput, getProjectExplorationResult, listProjectBranches, listProjectExplorations, listProjects } from '@pantheon/sdk';
|
|
4
|
+
import { getMe } from '@pantheon/sdk/api/auth';
|
|
5
|
+
import type { ApiParams, ApiRequestBody, ApiResponseBody } from '@pantheon/sdk/lib/api';
|
|
6
|
+
import { createApiExecutor, validateResponse } from '@pantheon/sdk/lib/api-executor';
|
|
7
|
+
import { branchSchema } from '@pantheon/sdk/schemas/branch';
|
|
8
|
+
import { paged } from '@pantheon/sdk/schemas/common';
|
|
9
|
+
import { explorationResultSchema, explorationSchema } from '@pantheon/sdk/schemas/exploration';
|
|
10
|
+
import { projectSchema } from '@pantheon/sdk/schemas/project';
|
|
11
|
+
import { z, type ZodType } from 'zod';
|
|
12
|
+
import packageJson from '../../package.json' with { type: 'json' };
|
|
13
|
+
|
|
14
|
+
export async function mcpServer ({
|
|
15
|
+
authorizationHeader,
|
|
16
|
+
}: {
|
|
17
|
+
authorizationHeader?: string
|
|
18
|
+
}) {
|
|
19
|
+
|
|
20
|
+
const executor = createApiExecutor({
|
|
21
|
+
baseUrl: 'https://pantheon-ai.tidb.ai/',
|
|
22
|
+
headers: authorizationHeader ? {
|
|
23
|
+
'Authorization': authorizationHeader,
|
|
24
|
+
} : undefined,
|
|
25
|
+
validateResponse: validateResponse,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
await executor.execute(getMe, null, null);
|
|
30
|
+
} catch {
|
|
31
|
+
throw 401;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const mcpServer = new McpServer({
|
|
35
|
+
name: 'Pantheon MCP',
|
|
36
|
+
version: packageJson.version,
|
|
37
|
+
websiteUrl: 'https://pantheon-ai.tidb.ai/',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function registerApiTool<
|
|
41
|
+
API extends Api<any, any, any, any>,
|
|
42
|
+
> (
|
|
43
|
+
name: string,
|
|
44
|
+
api: API,
|
|
45
|
+
{ paramsSchema, bodySchema, ...options }: {
|
|
46
|
+
title: string,
|
|
47
|
+
description?: string,
|
|
48
|
+
paramsSchema: ZodType<ApiParams<API>, any>,
|
|
49
|
+
bodySchema: ZodType<ApiRequestBody<API> extends void ? null : ApiRequestBody<API>, any>,
|
|
50
|
+
outputSchema: ZodType<ApiResponseBody<API>, any>,
|
|
51
|
+
},
|
|
52
|
+
) {
|
|
53
|
+
mcpServer.registerTool(name, {
|
|
54
|
+
...options,
|
|
55
|
+
inputSchema: z.object({
|
|
56
|
+
params: paramsSchema,
|
|
57
|
+
body: bodySchema,
|
|
58
|
+
}),
|
|
59
|
+
}, async ({ params, body }) => {
|
|
60
|
+
try {
|
|
61
|
+
const result = await executor.execute(api, params, body);
|
|
62
|
+
return {
|
|
63
|
+
content: [{ type: 'text', text: JSON.stringify(result) }],
|
|
64
|
+
structuredContent: result,
|
|
65
|
+
};
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: 'text', text: getErrorMessage(e) }],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
registerApiTool('listProjects', listProjects, {
|
|
75
|
+
title: 'List pantheon projects',
|
|
76
|
+
paramsSchema: pageParams,
|
|
77
|
+
bodySchema: z.null(),
|
|
78
|
+
outputSchema: paged(projectSchema),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
registerApiTool('createProject', createProject, {
|
|
82
|
+
title: 'Create pantheon project',
|
|
83
|
+
paramsSchema: z.null(),
|
|
84
|
+
bodySchema: z.object({
|
|
85
|
+
first_prompt: z.string(),
|
|
86
|
+
project_type: z.enum(['general', 'github']),
|
|
87
|
+
github_repo_id: z.number().optional(),
|
|
88
|
+
github_installation_id: z.number().optional(),
|
|
89
|
+
env_id: z.string().optional(),
|
|
90
|
+
}),
|
|
91
|
+
outputSchema: projectSchema,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
registerApiTool('listProjectBranches', listProjectBranches, {
|
|
95
|
+
title: 'List project branches',
|
|
96
|
+
paramsSchema: pageParams.extend({
|
|
97
|
+
projectId: z.string(),
|
|
98
|
+
}),
|
|
99
|
+
bodySchema: z.null(),
|
|
100
|
+
outputSchema: paged(branchSchema),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
registerApiTool('getProject', getProject, {
|
|
104
|
+
title: 'Get pantheon project',
|
|
105
|
+
paramsSchema: z.object({
|
|
106
|
+
projectId: z.string(),
|
|
107
|
+
}),
|
|
108
|
+
bodySchema: z.null(),
|
|
109
|
+
outputSchema: projectSchema,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
registerApiTool('getProjectBranch', getProjectBranch, {
|
|
113
|
+
title: 'Get pantheon project branch info',
|
|
114
|
+
paramsSchema: z.object({
|
|
115
|
+
projectId: z.string(),
|
|
116
|
+
branchId: z.string(),
|
|
117
|
+
}),
|
|
118
|
+
bodySchema: z.null(),
|
|
119
|
+
outputSchema: branchSchema,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
registerApiTool('getProjectBranchOutput', getProjectBranchOutput, {
|
|
123
|
+
title: 'Get pantheon project branch output',
|
|
124
|
+
paramsSchema: z.object({
|
|
125
|
+
projectId: z.string(),
|
|
126
|
+
branchId: z.string(),
|
|
127
|
+
fullOutput: z.boolean().optional().default(false),
|
|
128
|
+
}),
|
|
129
|
+
bodySchema: z.null(),
|
|
130
|
+
outputSchema: z.string(),
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
registerApiTool('createProjectExploration', createProjectExploration, {
|
|
134
|
+
title: 'Create pantheon project exploration',
|
|
135
|
+
paramsSchema: z.object({
|
|
136
|
+
projectId: z.string(),
|
|
137
|
+
}),
|
|
138
|
+
bodySchema: z.object({
|
|
139
|
+
parent_branch_id: z.string(),
|
|
140
|
+
shared_prompt_sequence: z.string().array().min(1).max(4),
|
|
141
|
+
num_branches: z.number().int().min(1).max(50).optional().default(3),
|
|
142
|
+
agent: z.string().optional(),
|
|
143
|
+
}),
|
|
144
|
+
outputSchema: explorationSchema,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
registerApiTool('listProjectExplorations', listProjectExplorations, {
|
|
148
|
+
title: 'List project explorations',
|
|
149
|
+
paramsSchema: z.object({
|
|
150
|
+
projectId: z.string(),
|
|
151
|
+
}),
|
|
152
|
+
bodySchema: z.null(),
|
|
153
|
+
outputSchema: explorationSchema.array(),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
registerApiTool('getProjectExplorationResult', getProjectExplorationResult, {
|
|
157
|
+
title: 'Get project exploration result',
|
|
158
|
+
paramsSchema: z.object({
|
|
159
|
+
projectId: z.string(),
|
|
160
|
+
explorationId: z.string(),
|
|
161
|
+
}),
|
|
162
|
+
bodySchema: z.null(),
|
|
163
|
+
outputSchema: explorationResultSchema,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return mcpServer;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const pageParams = z.object({
|
|
170
|
+
page: z.number().int().min(1),
|
|
171
|
+
size: z.number().int().min(1).max(100),
|
|
172
|
+
});
|
package/src/stdio.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
2
|
+
import { mcpServer } from './mcp/mcp.ts';
|
|
3
|
+
|
|
4
|
+
export async function startStdio ({ apiKey }: { apiKey: string }) {
|
|
5
|
+
const stdio = new StdioServerTransport();
|
|
6
|
+
const server = await mcpServer({
|
|
7
|
+
authorizationHeader: `Bearer ${apiKey}`,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
await server.connect(stdio);
|
|
11
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createMcpExpressApp } from '@modelcontextprotocol/sdk/server/express.js';
|
|
2
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
3
|
+
import { mcpServer } from './mcp/mcp.ts';
|
|
4
|
+
|
|
5
|
+
const port = process.env.PORT ? parseInt(process.env.PORT) : 9986;
|
|
6
|
+
|
|
7
|
+
export async function startStreamableHttpServer ({ apiKey }: { apiKey?: string }) {
|
|
8
|
+
const app = createMcpExpressApp();
|
|
9
|
+
|
|
10
|
+
app.all('/mcp', async (req, res) => {
|
|
11
|
+
const authorizationHeader = req.get('authorization') ?? (apiKey ? `Bearer ${apiKey}` : undefined);
|
|
12
|
+
let server: Awaited<ReturnType<typeof mcpServer>>;
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
server = await mcpServer({ authorizationHeader });
|
|
16
|
+
} catch (e) {
|
|
17
|
+
if (e === 401) {
|
|
18
|
+
res.status(400).send('401 Need Login');
|
|
19
|
+
return;
|
|
20
|
+
} else {
|
|
21
|
+
console.error('Error creating MCP server:', e);
|
|
22
|
+
res.status(500).send('Internal server error');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const transport = new StreamableHTTPServerTransport({
|
|
28
|
+
sessionIdGenerator: undefined,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
await server.connect(transport);
|
|
33
|
+
await transport.handleRequest(req, res, req.body);
|
|
34
|
+
|
|
35
|
+
res.on('close', () => {
|
|
36
|
+
transport.close();
|
|
37
|
+
server.close();
|
|
38
|
+
});
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Error handling MCP request:', error);
|
|
41
|
+
if (!res.headersSent) {
|
|
42
|
+
res.status(500).json({
|
|
43
|
+
jsonrpc: '2.0',
|
|
44
|
+
error: {
|
|
45
|
+
code: -32603,
|
|
46
|
+
message: 'Internal server error',
|
|
47
|
+
},
|
|
48
|
+
id: null,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
transport.close().catch(() => {});
|
|
52
|
+
server.close().catch(() => {});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
app.listen(port);
|
|
57
|
+
|
|
58
|
+
console.log('Listening on port 3001');
|
|
59
|
+
}
|
|
60
|
+
|