mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
basic UI rendering of MCP tools
This commit is contained in:
parent
1cf5cbab50
commit
b381dde9ac
5 changed files with 458 additions and 1 deletions
|
@ -4084,3 +4084,73 @@ export const updateInternalUserSettings = async (accessToken: string, settings:
|
|||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const listMCPTools = async (accessToken: string) => {
|
||||
try {
|
||||
// Construct base URL
|
||||
let url = proxyBaseUrl
|
||||
? `${proxyBaseUrl}/mcp/tools/list`
|
||||
: `/mcp/tools/list`;
|
||||
|
||||
console.log("Fetching MCP tools from:", url);
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
[globalLitellmHeaderName]: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.text();
|
||||
handleError(errorData);
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log("Fetched MCP tools:", data);
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch MCP tools:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const callMCPTool = async (accessToken: string, toolName: string, toolArguments: Record<string, any>) => {
|
||||
try {
|
||||
// Construct base URL
|
||||
let url = proxyBaseUrl
|
||||
? `${proxyBaseUrl}/mcp/tools/call`
|
||||
: `/mcp/tools/call`;
|
||||
|
||||
console.log("Calling MCP tool:", toolName, "with arguments:", toolArguments);
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
[globalLitellmHeaderName]: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
tool_name: toolName,
|
||||
tool_arguments: toolArguments,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.text();
|
||||
handleError(errorData);
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log("MCP tool call response:", data);
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Failed to call MCP tool:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue