Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58d30344f5 | ||
|
|
a6064035bd | ||
|
|
141fb4758f | ||
|
|
5450027bbc | ||
|
|
721a213bbf | ||
|
|
9ce81f5012 | ||
|
|
a28f3bb680 | ||
|
|
14e45235b4 | ||
|
|
6a69d678fd | ||
|
|
48ba7ffd96 | ||
|
|
faa1f552e6 | ||
|
|
b2bd2e30dd | ||
|
|
e25e119ba1 | ||
|
|
eb1811fa3a | ||
|
|
ee65da1665 | ||
|
|
bda95f756a | ||
|
|
ae7b6d20e4 | ||
|
|
0d1dff05d6 | ||
|
|
434518b2b3 | ||
|
|
3321efc3d4 | ||
|
|
0313ced503 |
No files matched your search
+3
-4
@@ -135,8 +135,7 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
networks:
|
||||
- xpack
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "8002:8002"
|
||||
- "8000:80"
|
||||
depends_on:
|
||||
- xpack-mysql
|
||||
- xpack-redis
|
||||
@@ -183,8 +182,8 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
|
||||
<br>
|
||||
|
||||
4. Im Browser über Port 3000 öffnen
|
||||
* **Admin‑Login**: http://{IP}:3000/admin-signin
|
||||
4. Im Browser über Port 8000 öffnen
|
||||
* **Admin‑Login**: http://{IP}:8000/admin-signin
|
||||
* **Benutzer**: admin
|
||||
* **Passwort**: 123456789
|
||||
</details>
|
||||
|
||||
+1
-2
@@ -136,8 +136,7 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
networks:
|
||||
- xpack
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "8002:8002"
|
||||
- "8000:80"
|
||||
depends_on:
|
||||
- xpack-mysql
|
||||
- xpack-redis
|
||||
|
||||
+3
-4
@@ -135,8 +135,7 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
networks:
|
||||
- xpack
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "8002:8002"
|
||||
- "8000:80"
|
||||
depends_on:
|
||||
- xpack-mysql
|
||||
- xpack-redis
|
||||
@@ -183,8 +182,8 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
|
||||
<br>
|
||||
|
||||
4. Accédez à l’interface sur le port 3000
|
||||
* **Connexion admin** : http://{IP}:3000/admin-signin
|
||||
4. Accédez à l’interface sur le port 8000
|
||||
* **Connexion admin** : http://{IP}:8000/admin-signin
|
||||
* **Utilisateur** : admin
|
||||
* **Mot de passe** : 123456789
|
||||
</details>
|
||||
|
||||
+3
-4
@@ -135,8 +135,7 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
networks:
|
||||
- xpack
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "8002:8002"
|
||||
- "8000:80"
|
||||
depends_on:
|
||||
- xpack-mysql
|
||||
- xpack-redis
|
||||
@@ -183,8 +182,8 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
|
||||
<br>
|
||||
|
||||
4. ブラウザでポート 3000 にアクセス
|
||||
* **管理画面ログイン**: http://{IP}:3000/admin-signin
|
||||
4. ブラウザでポート 8000 にアクセス
|
||||
* **管理画面ログイン**: http://{IP}:8000/admin-signin
|
||||
* **管理ユーザー**: admin
|
||||
* **管理パスワード**: 123456789
|
||||
</details>
|
||||
|
||||
+3
-4
@@ -135,8 +135,7 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
networks:
|
||||
- xpack
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "8002:8002"
|
||||
- "8000:80"
|
||||
depends_on:
|
||||
- xpack-mysql
|
||||
- xpack-redis
|
||||
@@ -183,8 +182,8 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
|
||||
<br>
|
||||
|
||||
4. 브라우저에서 3000 포트로 접속
|
||||
* **관리자 로그인 주소**: http://{IP}:3000/admin-signin
|
||||
4. 브라우저에서 8000 포트로 접속
|
||||
* **관리자 로그인 주소**: http://{IP}:8000/admin-signin
|
||||
* **관리자 계정**: admin
|
||||
* **관리자 비밀번호**: 123456789
|
||||
</details>
|
||||
|
||||
+2
-2
@@ -100,7 +100,7 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
|
||||
支持系统包括:
|
||||
- CentOS 7.9 / 8.5
|
||||
- Ubuntu 20.04 / 22.04
|
||||
- Ubuntu 20.04 / 22.04 / 24.04
|
||||
- Debian 12.4
|
||||
- 阿里云 Linux 2.1903 / 3.2104
|
||||
|
||||
@@ -125,7 +125,7 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
4. 打开浏览器访问 `http://localhost:3000` 使用平台
|
||||
4. 打开浏览器访问 `http://localhost:8000` 使用平台
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
+3
-4
@@ -136,8 +136,7 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
networks:
|
||||
- xpack
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "8002:8002"
|
||||
- "8000:80"
|
||||
depends_on:
|
||||
- xpack-mysql
|
||||
- xpack-redis
|
||||
@@ -184,8 +183,8 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
|
||||
<br>
|
||||
|
||||
4. 瀏覽器透過 3000 埠連線
|
||||
* **管理員登入**:http://{IP}:3000/admin-signin
|
||||
4. 瀏覽器透過 8000 埠連線
|
||||
* **管理員登入**:http://{IP}:8000/admin-signin
|
||||
* **帳號**:admin
|
||||
* **密碼**:123456789
|
||||
</details>
|
||||
|
||||
@@ -141,8 +141,7 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
networks:
|
||||
- xpack
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "8002:8002"
|
||||
- "8000:80" # Map port 8000 of the container to port 80 of the host, if you want to access XPack-MCP-Market in your browser at port 8000
|
||||
depends_on:
|
||||
- xpack-mysql
|
||||
- xpack-redis
|
||||
@@ -190,9 +189,9 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
|
||||
<br>
|
||||
|
||||
4. Access `XPack-MCP-Market` in your browser at port 3000
|
||||
4. Access `XPack-MCP-Market` in your browser at port 8000
|
||||
|
||||
* **Admin User Login Address**: http://{IP}:3000/admin
|
||||
* **Admin User Login Address**: http://{IP}:8000/admin
|
||||
* **Admin User**: admin
|
||||
* **Admin Password**: 123456789
|
||||
</details>
|
||||
@@ -213,8 +212,16 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
> Requirements:
|
||||
> - Node >= 22.x
|
||||
> - Pnpm >= 10.x
|
||||
|
||||
1. Execute the frontend build script
|
||||
1. Configure environment variable NEXT_PUBLIC_API_URL:
|
||||
```
|
||||
vi frontend/.env
|
||||
```
|
||||
|
||||
File content:
|
||||
```
|
||||
NEXT_PUBLIC_API_URL=http://127.0.0.1:8001
|
||||
```
|
||||
2. Execute the frontend build script
|
||||
```
|
||||
cd scripts && ./frontend_build.sh && cd ../
|
||||
```
|
||||
@@ -270,7 +277,7 @@ curl -sSO https://xpack.ai/install/quick-start.sh; bash quick-start.sh
|
||||
```
|
||||
### Docker Build
|
||||
```
|
||||
docker build -t xpack-mcp-market --build-arg APP=xpack-mcp-market --build-arg VERSION=1.0.0 -f ./scripts/Dockerfile ./
|
||||
docker build -t xpack-mcp-market --build-arg APP=xpack-mcp-market --build-arg VERSION=1.1.0 -f ./scripts/Dockerfile ./
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
+14
-12
@@ -19,18 +19,20 @@ const nextConfig = {
|
||||
async redirects() {
|
||||
return [];
|
||||
},
|
||||
// async rewrites() {
|
||||
// return [
|
||||
// {
|
||||
// source: "/api/:path*",
|
||||
// destination: `${process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"}/api/:path*`,
|
||||
// },
|
||||
// {
|
||||
// source: "/uploads/:path*",
|
||||
// destination: `${process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"}/uploads/:path*`,
|
||||
// },
|
||||
// ];
|
||||
// },
|
||||
async rewrites() {
|
||||
return [
|
||||
// {
|
||||
// source: "/api/:path*",
|
||||
// destination: `${process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"}/api/:path*`,
|
||||
// },
|
||||
{
|
||||
source: "/uploads/:path*",
|
||||
destination: `${
|
||||
process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"
|
||||
}/uploads/:path*`,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
// Headers for better performance
|
||||
async headers() {
|
||||
|
||||
@@ -876,5 +876,6 @@
|
||||
"Password must be at least 6 characters": "Password must be at least 6 characters",
|
||||
"Email is required": "Email is required",
|
||||
"No servers available": "No servers available",
|
||||
"(Deleted)": "(Deleted)"
|
||||
"(Deleted)": "(Deleted)",
|
||||
"Transport Type": "Transport Type"
|
||||
}
|
||||
@@ -878,5 +878,6 @@
|
||||
"Password must be at least 6 characters": "密码必须至少6个字符",
|
||||
"Email is required": "邮箱为必填项",
|
||||
"No servers available": "没有可用服务",
|
||||
"(Deleted)": "(已删除)"
|
||||
"(Deleted)": "(已删除)",
|
||||
"Transport Type": "传输方式"
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import Link from "next/link";
|
||||
import { Price } from "@/shared/components/marketplace/Price";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
||||
|
||||
interface DetailProps {
|
||||
product: ServiceData;
|
||||
@@ -214,40 +215,11 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
</h3>
|
||||
</div>
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full max-w-2xl bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<div className="flex items-center gap-2 mb-2 justify-between">
|
||||
<Chip className="text-white" size="sm" variant="flat">
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="flat"
|
||||
className="min-w-6 w-6 h-6 p-0 text-white"
|
||||
onPress={onCopy}
|
||||
aria-label={t("Copy code")}
|
||||
>
|
||||
<Copy size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="p-2 sm:p-4 rounded-md text-xs overflow-x-auto">
|
||||
<code className="text-gray-300 whitespace-pre-wrap">
|
||||
{`{
|
||||
"mcpServers": {
|
||||
"${mcpName}": {
|
||||
"type": "sse",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?authkey=`}
|
||||
<span className="text-success">{`{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
||||
{`"
|
||||
}
|
||||
}
|
||||
}`}
|
||||
</code>
|
||||
</pre>
|
||||
</div>
|
||||
</Card>
|
||||
<ServerConfig
|
||||
mcpName={mcpName}
|
||||
url={url}
|
||||
className="w-full max-w-2xl"
|
||||
/>
|
||||
</CardBody>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -162,7 +162,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<CardBody className="p-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between mb-3">
|
||||
<div className="flex items-center gap-2 w-full">
|
||||
<div className="flex items-center gap-2 w-full overflow-hidden">
|
||||
<div className="w-8 h-8 bg-slate-600 rounded-sm flex items-center justify-center">
|
||||
<Star className="w-4 h-4 text-white" />
|
||||
</div>
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Navigation } from "./Navigation";
|
||||
import { Footer } from "./Footer";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
||||
|
||||
interface DetailProps {
|
||||
product: ServiceData;
|
||||
@@ -174,40 +175,11 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
</h3>
|
||||
</div>
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full max-w-2xl bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<div className="flex items-center gap-2 mb-2 justify-between">
|
||||
<Chip className="text-white" size="sm" variant="flat">
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="flat"
|
||||
className="min-w-6 w-6 h-6 p-0 text-white"
|
||||
onPress={onCopy}
|
||||
aria-label={t("Copy code")}
|
||||
>
|
||||
<Copy size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="p-2 sm:p-4 rounded-md text-xs overflow-x-auto">
|
||||
<code className="text-gray-300 whitespace-pre-wrap">
|
||||
{`{
|
||||
"mcpServers": {
|
||||
"${mcpName}": {
|
||||
"type": "sse",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?authkey=`}
|
||||
<span className="text-success">{`{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
||||
{`"
|
||||
}
|
||||
}
|
||||
}`}
|
||||
</code>
|
||||
</pre>
|
||||
</div>
|
||||
</Card>
|
||||
<ServerConfig
|
||||
mcpName={mcpName}
|
||||
url={url}
|
||||
className="w-full max-w-2xl"
|
||||
/>
|
||||
</CardBody>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -13,6 +13,7 @@ import { Navigation } from "./Navigation";
|
||||
import { Footer } from "./Footer";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
||||
|
||||
interface DetailProps {
|
||||
product: ServiceData;
|
||||
@@ -141,40 +142,11 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
</h3>
|
||||
</div>
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full max-w-2xl bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<div className="flex items-center gap-2 mb-2 justify-between">
|
||||
<Chip className="text-white" size="sm" variant="flat">
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="flat"
|
||||
className="min-w-6 w-6 h-6 p-0 text-white"
|
||||
onPress={onCopy}
|
||||
aria-label={t("Copy code")}
|
||||
>
|
||||
<Copy size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="p-2 sm:p-4 rounded-md text-xs overflow-x-auto">
|
||||
<code className="text-gray-300 whitespace-pre-wrap">
|
||||
{`{
|
||||
"mcpServers": {
|
||||
"${mcpName}": {
|
||||
"type": "sse",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?authkey=`}
|
||||
<span className="text-success">{`{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
||||
{`"
|
||||
}
|
||||
}
|
||||
}`}
|
||||
</code>
|
||||
</pre>
|
||||
</div>
|
||||
</Card>
|
||||
<ServerConfig
|
||||
mcpName={mcpName}
|
||||
url={url}
|
||||
className="w-full max-w-2xl"
|
||||
/>
|
||||
</CardBody>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -168,7 +168,7 @@ export const Home: React.FC<HomeProps> = ({
|
||||
<CardBody className="p-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between mb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex items-center gap-2 overflow-hidden">
|
||||
<div className="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center">
|
||||
<Zap className="w-4 h-4 text-blue-600" />
|
||||
</div>
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Navigation } from "./Navigation";
|
||||
import { Footer } from "./Footer";
|
||||
import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
||||
import { NavigationItem } from "@/shared/components/Navigation";
|
||||
import { ServerConfig } from "@/shared/components/marketplace/ServerConfig";
|
||||
|
||||
interface DetailProps {
|
||||
product: ServiceData;
|
||||
@@ -161,40 +162,11 @@ export const Detail: React.FC<DetailProps> = ({
|
||||
>
|
||||
<div className="p-6">
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<div className="flex items-center gap-2 mb-2 justify-between">
|
||||
<Chip className="text-white" size="sm" variant="flat">
|
||||
{platformConfig?.name} MCP
|
||||
</Chip>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
variant="flat"
|
||||
className="min-w-6 w-6 h-6 p-0 text-white"
|
||||
onPress={onCopy}
|
||||
aria-label={t("Copy code")}
|
||||
>
|
||||
<Copy size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
<pre className="p-2 sm:p-4 rounded-md text-xs overflow-x-auto">
|
||||
<code className="text-gray-300 whitespace-pre-wrap">
|
||||
{`{
|
||||
"mcpServers": {
|
||||
"${mcpName}": {
|
||||
"type": "sse",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?authkey=`}
|
||||
<span className="text-success">{`{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
||||
{`"
|
||||
}
|
||||
}
|
||||
}`}
|
||||
</code>
|
||||
</pre>
|
||||
</div>
|
||||
</Card>
|
||||
<ServerConfig
|
||||
mcpName={mcpName}
|
||||
url={url}
|
||||
className="w-full max-w-2xl"
|
||||
/>
|
||||
</div>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { Card, Chip, Button } from "@nextui-org/react";
|
||||
import React, { useState } from "react";
|
||||
import { Card, Chip, Button, Select, SelectItem } from "@nextui-org/react";
|
||||
import { FlipButton } from "@/shared/components/FlipButton";
|
||||
import { useAuth } from "@/shared/lib/useAuth";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -13,23 +13,38 @@ import toast from "react-hot-toast";
|
||||
interface ServerConfigProps {
|
||||
mcpName?: string;
|
||||
url?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
type McpType = "sse" | "streamable-http";
|
||||
|
||||
export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||
mcpName,
|
||||
url = process.env.NEXT_PUBLIC_MCP_URL,
|
||||
className = "md:min-w-[40%] w-[40%] max-w-100 mt-12",
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const { handleLogin } = useAuth();
|
||||
const { platformConfig } = usePlatformConfig();
|
||||
const [mcpType, setMcpType] = useState<McpType>("sse");
|
||||
|
||||
const mcpTypeOptions = [
|
||||
{ key: "sse", label: "SSE (Server-Sent Events)" },
|
||||
{ key: "streamable-http", label: "Streamable HTTP" },
|
||||
];
|
||||
|
||||
const getCodeContent = () => {
|
||||
const serverUrl =
|
||||
mcpType === "streamable-http"
|
||||
? `${url}/streamable-http?authkey={Your-${platformConfig?.name}-Auth-Key}`
|
||||
: `${url}?authkey={Your-${platformConfig?.name}-Auth-Key}`;
|
||||
|
||||
return `{
|
||||
"mcpServers": {
|
||||
"${mcpName || "xpack-mcp-market"}": {
|
||||
"type": "sse",
|
||||
"type": "${mcpType}",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?authkey={Your-${platformConfig?.name}-Auth-Key}"
|
||||
"url": "${serverUrl}"
|
||||
}
|
||||
}
|
||||
}`;
|
||||
@@ -45,8 +60,8 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-w-full md:min-w-[40%] w-[40%] max-w-100 flex-shrink-0 mt-12">
|
||||
<div className="mb-4 mt-1">
|
||||
<div className={`min-w-full ${className} flex-shrink-0`}>
|
||||
<div className="mb-2 mt-1">
|
||||
<FlipButton
|
||||
className="w-full rounded-md"
|
||||
text={t("Sign up to get the auth key")}
|
||||
@@ -54,8 +69,35 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* MCP Type Selection */}
|
||||
<div className="mb-2">
|
||||
<Select
|
||||
label={t("Transport Type")}
|
||||
placeholder={t("Select MCP transport type")}
|
||||
selectedKeys={[mcpType]}
|
||||
onSelectionChange={(keys) => {
|
||||
const selectedKey = Array.from(keys)[0] as McpType;
|
||||
setMcpType(selectedKey);
|
||||
}}
|
||||
className="w-full"
|
||||
size="sm"
|
||||
classNames={{
|
||||
trigger: " bg-black text-white data-[hover=true]:bg-dark-200",
|
||||
label: "!text-default-200",
|
||||
value: "!text-white",
|
||||
popoverContent: "bg-black text-white",
|
||||
}}
|
||||
>
|
||||
{mcpTypeOptions.map((option) => (
|
||||
<SelectItem key={option.key} value={option.key}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* Code Snippet */}
|
||||
<Card className="w-full max-w-2xl bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<Card className="w-full bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
|
||||
<div className="text-left font-mono">
|
||||
<div className="flex items-center gap-2 mb-2 justify-between">
|
||||
<Chip className="text-white" size="sm" variant="flat">
|
||||
@@ -77,9 +119,12 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||
{`{
|
||||
"mcpServers": {
|
||||
"${mcpName || "xpack-mcp-market"}": {
|
||||
"type": "sse",
|
||||
"type": "${mcpType}",
|
||||
"autoApprove":"all",
|
||||
"url": "${url}?authkey=`}
|
||||
"url": "`}
|
||||
{mcpType === "streamable-http"
|
||||
? `${url}/streamable-http?authkey=`
|
||||
: `${url}?authkey=`}
|
||||
<span className="text-success">{`{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
||||
{`"
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ services:
|
||||
networks:
|
||||
- xpack
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "8002:8002"
|
||||
- "8000:80"
|
||||
depends_on:
|
||||
- xpack-mysql
|
||||
- xpack-redis
|
||||
|
||||
@@ -39,7 +39,7 @@ MYSQL_DATA_MOUNT="/var/lib/xpack/mysql"
|
||||
REDIS_PASSWORD="redis_6sJZDm"
|
||||
REDIS_MAP_PORT=6379
|
||||
|
||||
XPACK_MCP_MARKET_MAP_PORT=3000
|
||||
XPACK_MCP_MARKET_MAP_PORT=8000
|
||||
|
||||
RABBITMQ_USER="rabbitmq"
|
||||
RABBITMQ_PASSWORD="rabbitmq_Gs123dA"
|
||||
@@ -1064,8 +1064,9 @@ operate() {
|
||||
Install_Deb_Pack
|
||||
fi
|
||||
write_ip_env
|
||||
sleep 5s
|
||||
#sleep 5s
|
||||
echo_info "start docker..."
|
||||
systemctl reset-failed docker.service
|
||||
systemctl start docker
|
||||
echo_info "start network..."
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ MYSQL_PASSWORD=mysql_ZTdhRB
|
||||
MYSQL_DB=xpack
|
||||
|
||||
# 服务端口配置
|
||||
API_PORT=8000
|
||||
API_PORT=8002
|
||||
ADMIN_PORT=8001
|
||||
|
||||
# 调试配置
|
||||
|
||||
@@ -34,11 +34,11 @@ fi
|
||||
# 初始化数据库
|
||||
python ./init_db.py
|
||||
|
||||
nohup uvicorn services.admin_service.main:app --host 0.0.0.0 --port 8001 --reload > ${LOG_DIR}/admin_service.log 2>&1 &
|
||||
nohup uvicorn services.admin_service.main:app --host 0.0.0.0 --port 8001 --reload --timeout-graceful-shutdown 2 --timeout-keep-alive 1 > ${LOG_DIR}/admin_service.log 2>&1 &
|
||||
|
||||
sleep 5s
|
||||
|
||||
nohup uvicorn services.api_service.main:app --host 0.0.0.0 --port 8002 --reload > ${LOG_DIR}/api_service.log 2>&1 &
|
||||
nohup uvicorn services.api_service.main:app --host 0.0.0.0 --port 8002 --reload --timeout-graceful-shutdown 2 --timeout-keep-alive 1 > ${LOG_DIR}/api_service.log 2>&1 &
|
||||
HOSTNAME=""
|
||||
cd frontend/ && nohup node server.js> ${LOG_DIR}//frontend.log 2>&1 &
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"downloads": {
|
||||
"program": {
|
||||
"xpack_mcp_market": {
|
||||
"version": "v1.1.0",
|
||||
"version": "v1.1.1",
|
||||
"docker": "xpackai/xpack-mcp-market",
|
||||
"tar": "xpack-mcp-market.tar.gz",
|
||||
"url": "https://public.eolinker.com/xpack/images/xpack-mcp-market.${VERSION}.${ARCH}.tar.gz"
|
||||
|
||||
@@ -147,7 +147,7 @@ app.add_middleware(AuthMiddleware)
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_credentials=False,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
@@ -172,8 +172,8 @@ class McpManagerService:
|
||||
new_api.response_examples = temp_api.response_examples
|
||||
new_api.response_headers = temp_api.response_headers
|
||||
new_api.operation_examples = temp_api.operation_examples
|
||||
new_api.enabled = temp_api.enabled
|
||||
new_api.is_deleted = temp_api.is_deleted
|
||||
new_api.enabled = True
|
||||
# new_api.is_deleted = temp_api.is_deleted
|
||||
|
||||
# Save new API record
|
||||
self.mcp_tool_api_repository.create(new_api)
|
||||
|
||||
@@ -8,12 +8,16 @@ from datetime import datetime, timezone
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import Response
|
||||
import asyncio
|
||||
import time
|
||||
from mcp.server.sse import SseServerTransport
|
||||
from mcp.server.streamable_http import StreamableHTTPServerTransport
|
||||
from mcp.server.lowlevel import Server
|
||||
from services.api_service.services.mcp_server_factory import McpServerFactory
|
||||
from services.common.logging_config import get_logger
|
||||
from services.api_service.repositories.user_apikey_repository import UserApiKeyRepository
|
||||
from services.api_service.utils.connection_manager import connection_manager
|
||||
from services.common.database import get_db
|
||||
from services.common.config import Config
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -23,7 +27,17 @@ class McpController:
|
||||
|
||||
def __init__(self):
|
||||
self.sse = SseServerTransport("/messages/")
|
||||
# StreamableHTTP session persistence: store transport and server task keyed by (service_id, user_id)
|
||||
self._http_transports: dict[str, StreamableHTTPServerTransport] = {}
|
||||
self._http_server_tasks: dict[str, asyncio.Task] = {}
|
||||
self._http_servers: dict[str, Server] = {}
|
||||
self.server_factory = McpServerFactory()
|
||||
# Session recycling: track idle time and run a background cleanup task
|
||||
self._session_last_activity: dict[str, float] = {}
|
||||
self._session_gc_task: Optional[asyncio.Task] = None
|
||||
self._session_gc_stop_event = asyncio.Event()
|
||||
self._session_idle_ttl = getattr(Config, "MCP_SESSION_IDLE_TTL_SECONDS", 900)
|
||||
self._session_cleanup_interval = getattr(Config, "MCP_SESSION_CLEANUP_INTERVAL_SECONDS", 60)
|
||||
|
||||
async def handle_sse_connection(self, request: Request):
|
||||
"""Handle MCP Streamable HTTP SSE connection with resume capability."""
|
||||
@@ -114,9 +128,8 @@ class McpController:
|
||||
async def handle_sse_connection_asgi(self, request: Request):
|
||||
"""Return an ASGI app that handles MCP SSE connections.
|
||||
|
||||
Starlette's Route will call this with a Request and then treat
|
||||
the returned callable as an ASGI app. We implement the SSE handshake
|
||||
and streaming within the returned ASGI callable using scope/receive/send.
|
||||
Starlette Route passes a Request and treats the returned callable as an ASGI app.
|
||||
The returned ASGI callable performs the SSE handshake and runs the MCP server.
|
||||
"""
|
||||
|
||||
async def asgi(scope, receive, send):
|
||||
@@ -160,10 +173,6 @@ class McpController:
|
||||
|
||||
user_id, apikey_id = user_info
|
||||
|
||||
# Get apikey for logging (extract first 10 characters for audit)
|
||||
apikey = req.query_params.get("apikey", "") or req.query_params.get("authkey", "")
|
||||
apikey_for_log = apikey[:10] if apikey else None
|
||||
|
||||
# Create MCP server instance (pass user_id and apikey_id for billing and logging)
|
||||
mcp_server = await self.server_factory.create_server(service_id, user_id, apikey_id)
|
||||
|
||||
@@ -195,8 +204,6 @@ class McpController:
|
||||
# Unregister connection
|
||||
connection_manager.unregister_connection(connection_key)
|
||||
|
||||
# End of ASGI callable; no further Response needed
|
||||
|
||||
except ConnectionError as e:
|
||||
logger.warning(f"Connection error - Service ID: {service_id or 'unknown'}, Client: {client_ip}: {str(e)}")
|
||||
response_body = b"Connection error"
|
||||
@@ -224,6 +231,194 @@ class McpController:
|
||||
|
||||
return asgi
|
||||
|
||||
async def handle_streamable_http_asgi(self, request: Request):
|
||||
"""Return an ASGI app that handles MCP Streamable HTTP (GET/POST/DELETE).
|
||||
|
||||
Delegate requests to StreamableHTTP's handle_request; use persistent transport and server
|
||||
so GET/POST/DELETE interact within the same session, ensuring tools/resources queries
|
||||
return to the same SSE stream.
|
||||
"""
|
||||
|
||||
async def asgi(scope, receive, send):
|
||||
req = Request(scope)
|
||||
client_ip = req.client.host if req.client else "unknown"
|
||||
user_agent = req.headers.get("user-agent", "unknown")
|
||||
service_id = None
|
||||
session_key = None
|
||||
|
||||
try:
|
||||
# Extract service_id from URL path (supports both ID and slug_name)
|
||||
service_id = self._extract_service_id(req)
|
||||
if not service_id:
|
||||
response_body = b"Missing service_id parameter or service not found"
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 400,
|
||||
'headers': [
|
||||
[b'content-type', b'text/plain'],
|
||||
[b'content-length', str(len(response_body)).encode()],
|
||||
],
|
||||
})
|
||||
await send({'type': 'http.response.body', 'body': response_body})
|
||||
return
|
||||
|
||||
logger.info(f"Received StreamableHTTP request - Service ID: {service_id}, Client: {client_ip}, UA: {user_agent[:50]}...")
|
||||
|
||||
# Extract user ID (for billing) - must provide valid apikey
|
||||
user_info = self._extract_user_info(req)
|
||||
if not user_info:
|
||||
response_body = b"Missing or invalid apikey parameter"
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 401,
|
||||
'headers': [
|
||||
[b'content-type', b'text/plain'],
|
||||
[b'content-length', str(len(response_body)).encode()],
|
||||
],
|
||||
})
|
||||
await send({'type': 'http.response.body', 'body': response_body})
|
||||
return
|
||||
|
||||
user_id, apikey_id = user_info
|
||||
session_key = f"{service_id}:{user_id}"
|
||||
|
||||
# Build connection key for lifecycle management
|
||||
connection_key = f"{service_id}:{user_id}:{client_ip}"
|
||||
|
||||
try:
|
||||
# Get or create a persistent StreamableHTTP transport and MCP server
|
||||
transport = await self._ensure_http_session(session_key, service_id, user_id, apikey_id)
|
||||
|
||||
# Note session activity
|
||||
self._note_session_activity(session_key)
|
||||
|
||||
# Register only on GET (SSE handshake); POST just updates activity
|
||||
if req.method == "GET":
|
||||
connection_manager.register_connection(service_id, user_id, client_ip)
|
||||
elif req.method == "POST":
|
||||
connection_manager.update_activity(connection_key)
|
||||
|
||||
# Delegate request to transport; GET establishes SSE; POST sends JSON-RPC; DELETE terminates the session
|
||||
await transport.handle_request(scope, receive, send)
|
||||
|
||||
# Update activity after handling (avoid cleaning long-running processing)
|
||||
self._note_session_activity(session_key)
|
||||
|
||||
# If the session has terminated or DELETE called, clean up and unregister
|
||||
if transport.is_terminated or req.method == "DELETE":
|
||||
await self._cleanup_http_session(session_key)
|
||||
connection_manager.unregister_connection(connection_key)
|
||||
finally:
|
||||
# Unregister when SSE GET disconnects
|
||||
if req.method == "GET":
|
||||
connection_manager.unregister_connection(connection_key)
|
||||
|
||||
except ConnectionError as e:
|
||||
logger.warning(f"Connection error - Service ID: {service_id or 'unknown'}, Client: {client_ip}: {str(e)}")
|
||||
response_body = b"Connection error"
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 503,
|
||||
'headers': [
|
||||
[b'content-type', b'text/plain'],
|
||||
[b'content-length', str(len(response_body)).encode()],
|
||||
],
|
||||
})
|
||||
await send({'type': 'http.response.body', 'body': response_body})
|
||||
except Exception as e:
|
||||
logger.error(f"StreamableHTTP handling failed - Service ID: {service_id or 'unknown'}, Client: {client_ip}: {str(e)}", exc_info=True)
|
||||
response_body = f"Internal server error: {str(e)}".encode('utf-8')
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 500,
|
||||
'headers': [
|
||||
[b'content-type', b'text/plain'],
|
||||
[b'content-length', str(len(response_body)).encode()],
|
||||
],
|
||||
})
|
||||
await send({'type': 'http.response.body', 'body': response_body})
|
||||
|
||||
return asgi
|
||||
|
||||
async def _ensure_http_session(self, session_key: str, service_id: str, user_id: str, apikey_id: str) -> StreamableHTTPServerTransport:
|
||||
"""Ensure a persistent StreamableHTTP transport and MCP server exist for the session.
|
||||
|
||||
- Create or reuse the transport
|
||||
- If the server has not been started, start mcp_server.run() within transport.connect()
|
||||
"""
|
||||
if session_key in self._http_transports:
|
||||
transport = self._http_transports[session_key]
|
||||
# Start GC task if not started
|
||||
self._ensure_session_gc_task()
|
||||
# Note activity
|
||||
self._note_session_activity(session_key)
|
||||
# If the server task exists and is not finished, reuse it
|
||||
task = self._http_server_tasks.get(session_key)
|
||||
if task and not task.done():
|
||||
return transport
|
||||
# If no task or the task is finished, restart
|
||||
mcp_server = self._http_servers.get(session_key)
|
||||
if mcp_server is None:
|
||||
mcp_server = await self.server_factory.create_server(service_id, user_id, apikey_id)
|
||||
self._http_servers[session_key] = mcp_server
|
||||
init_options = mcp_server.create_initialization_options()
|
||||
init_options.server_name = f"mcp-service-{service_id}"
|
||||
|
||||
async def run_server():
|
||||
async with transport.connect() as (read_stream, write_stream):
|
||||
try:
|
||||
await mcp_server.run(read_stream, write_stream, init_options)
|
||||
except asyncio.CancelledError:
|
||||
logger.info(f"MCP server task cancelled - Service: {service_id}, User: {user_id}")
|
||||
except Exception as e:
|
||||
logger.error(f"MCP server task error: {e}", exc_info=True)
|
||||
|
||||
task = asyncio.create_task(run_server())
|
||||
self._http_server_tasks[session_key] = task
|
||||
return transport
|
||||
|
||||
# Create transport and server
|
||||
transport = StreamableHTTPServerTransport(mcp_session_id=None, is_json_response_enabled=False)
|
||||
mcp_server = await self.server_factory.create_server(service_id, user_id, apikey_id)
|
||||
self._http_transports[session_key] = transport
|
||||
self._http_servers[session_key] = mcp_server
|
||||
|
||||
init_options = mcp_server.create_initialization_options()
|
||||
init_options.server_name = f"mcp-service-{service_id}"
|
||||
logger.info(f"StreamableHTTP session created - Service: {service_id}, User: {user_id}")
|
||||
|
||||
# Start GC task if not started and note activity
|
||||
self._ensure_session_gc_task()
|
||||
self._note_session_activity(session_key)
|
||||
|
||||
async def run_server():
|
||||
async with transport.connect() as (read_stream, write_stream):
|
||||
try:
|
||||
await mcp_server.run(read_stream, write_stream, init_options)
|
||||
except asyncio.CancelledError:
|
||||
logger.info(f"MCP server task cancelled - Service: {service_id}, User: {user_id}")
|
||||
except Exception as e:
|
||||
logger.error(f"MCP server task error: {e}", exc_info=True)
|
||||
|
||||
task = asyncio.create_task(run_server())
|
||||
self._http_server_tasks[session_key] = task
|
||||
return transport
|
||||
|
||||
async def _cleanup_http_session(self, session_key: str) -> None:
|
||||
"""Cleanup transport and server task for a terminated session."""
|
||||
task = self._http_server_tasks.pop(session_key, None)
|
||||
transport = self._http_transports.pop(session_key, None)
|
||||
self._http_servers.pop(session_key, None)
|
||||
|
||||
if task and not task.done():
|
||||
try:
|
||||
# Terminate transport to prompt server exit
|
||||
if transport and not transport.is_terminated:
|
||||
await transport.terminate()
|
||||
await task
|
||||
except Exception:
|
||||
logger.exception("Error while waiting for server task to finish")
|
||||
|
||||
def _extract_service_id(self, request: Request) -> Optional[str]:
|
||||
"""Extract service ID from request path, supporting both ID and slug_name."""
|
||||
service_identifier = request.path_params.get("service_id")
|
||||
@@ -312,3 +507,48 @@ class McpController:
|
||||
def get_sse_mount_handler(self):
|
||||
"""Get SSE message handler for processing requests."""
|
||||
return self.sse.handle_post_message
|
||||
|
||||
def get_streamable_http_handler(self):
|
||||
# We no longer return a handler for a persistent instance; if needed, call
|
||||
# handle_streamable_http_asgi at the routing layer. This placeholder is
|
||||
# retained to avoid external references breaking, but it is not used.
|
||||
raise NotImplementedError("Use handle_streamable_http_asgi for StreamableHTTP routes")
|
||||
|
||||
|
||||
def _ensure_session_gc_task(self) -> None:
|
||||
"""Start background GC task if not already running."""
|
||||
if self._session_gc_task is None or self._session_gc_task.done():
|
||||
loop = asyncio.get_running_loop()
|
||||
self._session_gc_task = loop.create_task(self._run_session_gc())
|
||||
logger.info("Session GC task started")
|
||||
|
||||
def _note_session_activity(self, session_key: str) -> None:
|
||||
"""Update last activity timestamp for a session."""
|
||||
self._session_last_activity[session_key] = time.time()
|
||||
|
||||
async def _run_session_gc(self) -> None:
|
||||
"""Background task to recycle idle or terminated sessions."""
|
||||
try:
|
||||
while not self._session_gc_stop_event.is_set():
|
||||
await asyncio.sleep(self._session_cleanup_interval)
|
||||
now = time.time()
|
||||
stale_keys: list[str] = []
|
||||
for key, transport in list(self._http_transports.items()):
|
||||
last = self._session_last_activity.get(key, 0)
|
||||
idle = (now - last) > self._session_idle_ttl
|
||||
task = self._http_server_tasks.get(key)
|
||||
active_task = task is not None and not task.done()
|
||||
# Only TTL-clean when there is no active task, to avoid killing active SSE sessions
|
||||
if transport.is_terminated or (idle and not active_task):
|
||||
stale_keys.append(key)
|
||||
for key in stale_keys:
|
||||
logger.info(f"Recycling session {key} (terminated or idle > {self._session_idle_ttl}s)")
|
||||
try:
|
||||
await self._cleanup_http_session(key)
|
||||
except Exception:
|
||||
logger.exception("Error during session cleanup")
|
||||
self._session_last_activity.pop(key, None)
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
finally:
|
||||
logger.info("Session GC task stopped")
|
||||
@@ -102,7 +102,7 @@ app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"], # MCP clients may come from different domains
|
||||
allow_credentials=True,
|
||||
allow_methods=["GET", "POST", "OPTIONS"], # Add OPTIONS for preflight requests
|
||||
allow_methods=["GET", "POST", "DELETE", "OPTIONS"], # 添加 DELETE 支持 StreamableHTTP 终止
|
||||
allow_headers=["*"],
|
||||
expose_headers=["*"], # Expose all response headers for SSE reconnection
|
||||
)
|
||||
@@ -197,8 +197,9 @@ def mcp_connections_stats():
|
||||
# Create MCP Streamable HTTP routes
|
||||
# Use Starlette sub-app to handle MCP protocol's underlying SSE connections
|
||||
mcp_routes = [
|
||||
Route("/{service_id}", endpoint=mcp.handle_sse_connection_asgi, methods=["GET"]),
|
||||
Mount("/messages/", app=mcp.get_sse_mount_handler()),
|
||||
Route("/{service_id}", endpoint=mcp.handle_sse_connection_asgi, methods=["GET"]), # 保留原有 SSE GET
|
||||
Mount("/messages/", app=mcp.get_sse_mount_handler()), # 保留原有 SSE POST 挂载
|
||||
Route("/{service_id}/streamable-http", endpoint=mcp.handle_streamable_http_asgi, methods=["GET", "POST", "DELETE"]), # 新增 StreamableHTTP 路由
|
||||
]
|
||||
|
||||
mcp_app = Starlette(routes=mcp_routes)
|
||||
|
||||
@@ -50,15 +50,20 @@ class McpServerFactory:
|
||||
"""Return available tools list for this service"""
|
||||
return await self._handle_list_tools(service_id)
|
||||
|
||||
# Register resources list handler (optional, return empty when not configured)
|
||||
@app.list_resources()
|
||||
async def list_resources() -> List[types.Resource]:
|
||||
return []
|
||||
|
||||
# Register tool call handler
|
||||
@app.call_tool()
|
||||
async def call_tool(name: str, arguments: dict) -> List[types.Content]:
|
||||
async def call_tool(name: str, arguments: dict) -> tuple[List[types.Content], dict]:
|
||||
"""Execute specified tool"""
|
||||
# user_id must exist, otherwise we shouldn't reach here
|
||||
if not user_id:
|
||||
error_msg = "Missing user authentication"
|
||||
logger.error(error_msg)
|
||||
return [types.TextContent(type="text", text=error_msg)]
|
||||
return [types.TextContent(type="text", text=error_msg)], {}
|
||||
|
||||
return await self._handle_call_tool_with_billing(service_id, name, arguments, user_id, apikey_id)
|
||||
|
||||
@@ -97,7 +102,7 @@ class McpServerFactory:
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
async def _handle_call_tool_with_billing(self, service_id: str, name: str, arguments: dict, user_id: str, apikey_id: Optional[str] = None) -> List[types.Content]:
|
||||
async def _handle_call_tool_with_billing(self, service_id: str, name: str, arguments: dict, user_id: str, apikey_id: Optional[str] = None) -> tuple[List[types.Content], dict]:
|
||||
"""
|
||||
Handle tool call with billing logic
|
||||
|
||||
@@ -140,7 +145,7 @@ class McpServerFactory:
|
||||
|
||||
# If tool API id not found, skip sending billing message to avoid FK errors
|
||||
if not api_id_for_log:
|
||||
return [types.TextContent(type="text", text=error_msg)]
|
||||
return [types.TextContent(type="text", text=error_msg)], {}
|
||||
|
||||
call_log = ApiCallLogInfo(
|
||||
user_id=user_id,
|
||||
@@ -158,7 +163,7 @@ class McpServerFactory:
|
||||
)
|
||||
await self.billing_service.send_billing_message(call_log, False, datetime.now(timezone.utc))
|
||||
|
||||
return [types.TextContent(type="text", text=error_msg)]
|
||||
return [types.TextContent(type="text", text=error_msg)],{}
|
||||
|
||||
logger.info(f"Pre-deduction successful - User ID: {user_id}, Deduction amount: {pre_deduct_result.service_price}")
|
||||
amount = pre_deduct_result.service_price
|
||||
@@ -166,6 +171,7 @@ class McpServerFactory:
|
||||
db = next(get_db())
|
||||
call_success = False
|
||||
result: List[types.ContentBlock] = []
|
||||
response_data: dict = {}
|
||||
# calculate input token amount
|
||||
input_token_amount = Decimal("0")
|
||||
output_token_amount = Decimal("0")
|
||||
@@ -190,7 +196,7 @@ class McpServerFactory:
|
||||
logger.error(error_msg)
|
||||
# Close DB and return error without sending billing message to avoid FK violation
|
||||
db.close()
|
||||
return [types.TextContent(type="text", text=error_msg)]
|
||||
return [types.TextContent(type="text", text=error_msg)],{}
|
||||
|
||||
try:
|
||||
logger.info(f"Found tool configuration: {tool_config.name}")
|
||||
@@ -200,7 +206,7 @@ class McpServerFactory:
|
||||
logger.debug(f"Call params: {call_params}")
|
||||
|
||||
# Execute tool
|
||||
result = await self.tool_service.execute_tool(tool_config, arguments, call_params)
|
||||
result,response_data = await self.tool_service.execute_tool(tool_config, arguments, call_params)
|
||||
call_success = True
|
||||
logger.info(f"Tool call successful - User ID: {user_id}, Tool: {name}")
|
||||
|
||||
@@ -249,7 +255,7 @@ class McpServerFactory:
|
||||
logger.info(f"Billing message sent - User ID: {user_id}, Tool: {name}, Success: {call_success}")
|
||||
|
||||
# Ensure return type is correct
|
||||
return result
|
||||
return result,response_data
|
||||
|
||||
def _create_mcp_service(self, db) -> McpService:
|
||||
"""
|
||||
|
||||
@@ -131,11 +131,15 @@ class McpService:
|
||||
"required": []
|
||||
}
|
||||
|
||||
return types.Tool(
|
||||
t = types.Tool(
|
||||
name=tool_api.name,
|
||||
description=tool_api.description,
|
||||
inputSchema=input_schema
|
||||
inputSchema=input_schema,
|
||||
)
|
||||
output_schema = self._build_output_schema(tool_api)
|
||||
if output_schema:
|
||||
t.outputSchema = output_schema
|
||||
return t
|
||||
except Exception as e:
|
||||
self.logger.error(f"Tool conversion failed for {tool_api.name}: {e}")
|
||||
return None
|
||||
@@ -271,4 +275,62 @@ class McpService:
|
||||
return {
|
||||
"base_url": service.base_url or "",
|
||||
"headers": headers
|
||||
}
|
||||
}
|
||||
|
||||
def _build_output_schema(self,tool_api:McpToolApi) -> Optional[dict]:
|
||||
"""
|
||||
Build output schema based on API configuration
|
||||
|
||||
Priority:
|
||||
1) Use explicit JSON Schema from `response_schema` if present
|
||||
2) Infer a reasonable JSON Schema from `response_examples`
|
||||
3) Fallback to a generic text content schema
|
||||
"""
|
||||
# 1) Try explicit response schema
|
||||
try:
|
||||
if tool_api.response_schema:
|
||||
parsed = json.loads(tool_api.response_schema)
|
||||
if isinstance(parsed, dict):
|
||||
return parsed
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Failed to parse response_schema for {tool_api.name}: {e}")
|
||||
|
||||
# 2) Try to infer schema from examples
|
||||
try:
|
||||
if getattr(tool_api, "response_examples", None) and tool_api.response_examples.strip():
|
||||
examples = json.loads(tool_api.response_examples)
|
||||
# If multiple examples provided, use the first for inference
|
||||
example_value = examples[0] if isinstance(examples, list) and examples else examples
|
||||
inferred = self._infer_json_schema_from_example(example_value)
|
||||
if inferred:
|
||||
return inferred
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Failed to infer schema from response_examples for {tool_api.name}: {e}")
|
||||
|
||||
# 3) Fallback to a generic text MCP content schema
|
||||
return None
|
||||
|
||||
# Helper: Infer a simple JSON Schema from a Python value
|
||||
def _infer_json_schema_from_example(self, value) -> dict:
|
||||
try:
|
||||
if isinstance(value, str):
|
||||
return {"type": "string"}
|
||||
if isinstance(value, bool):
|
||||
return {"type": "boolean"}
|
||||
if isinstance(value, int):
|
||||
return {"type": "integer"}
|
||||
if isinstance(value, float):
|
||||
return {"type": "number"}
|
||||
if isinstance(value, list):
|
||||
if not value:
|
||||
return {"type": "array", "items": {}}
|
||||
# Infer from first element; for heterogeneous arrays this is a best-effort
|
||||
return {"type": "array", "items": self._infer_json_schema_from_example(value[0])}
|
||||
if isinstance(value, dict):
|
||||
props = {k: self._infer_json_schema_from_example(v) for k, v in value.items()}
|
||||
required = list(value.keys())
|
||||
return {"type": "object", "properties": props, "required": required}
|
||||
# Fallback
|
||||
return {"type": "string"}
|
||||
except Exception:
|
||||
return {"type": "string"}
|
||||
@@ -17,7 +17,7 @@ class McpToolService:
|
||||
def __init__(self):
|
||||
self.http_builder = HttpRequestBuilder()
|
||||
|
||||
async def execute_tool(self, tool_config, arguments: dict, call_params: dict) -> List[types.Content]:
|
||||
async def execute_tool(self, tool_config, arguments: dict, call_params: dict) -> tuple[List[types.Content],dict]:
|
||||
"""
|
||||
Execute tool call
|
||||
|
||||
@@ -37,14 +37,17 @@ class McpToolService:
|
||||
|
||||
# Send HTTP request
|
||||
response_text = await self._send_http_request(request_info)
|
||||
|
||||
if response_text:
|
||||
response_data = json.loads(response_text)
|
||||
else:
|
||||
response_data = {}
|
||||
logger.info("Tool execution completed successfully")
|
||||
return [types.TextContent(type="text", text=response_text)]
|
||||
return [types.TextContent(type="text", text=response_text)],response_data
|
||||
|
||||
except Exception as e:
|
||||
error_msg = f"Tool execution failed: {str(e)}"
|
||||
logger.error(f"Tool execution failed: {error_msg}", exc_info=True)
|
||||
return [types.TextContent(type="text", text=error_msg)]
|
||||
return [types.TextContent(type="text", text=error_msg)],{}
|
||||
|
||||
async def _send_http_request(self, request_info: Dict[str, Any]) -> str:
|
||||
"""
|
||||
@@ -81,6 +84,8 @@ class McpToolService:
|
||||
raise ValueError(f"Unsupported HTTP method: {method}")
|
||||
|
||||
logger.info(f"HTTP response status code: {response.status_code}")
|
||||
if response.text != "":
|
||||
logger.debug(f"Response content: {response.text}")
|
||||
response.raise_for_status()
|
||||
|
||||
response_text = response.text
|
||||
|
||||
@@ -73,3 +73,5 @@ class Config:
|
||||
"/uploads/",
|
||||
"/api/common/"
|
||||
]
|
||||
MCP_SESSION_IDLE_TTL_SECONDS = int(os.getenv("MCP_SESSION_IDLE_TTL_SECONDS", 900))
|
||||
MCP_SESSION_CLEANUP_INTERVAL_SECONDS = int(os.getenv("MCP_SESSION_CLEANUP_INTERVAL_SECONDS", 60))
|
||||
Reference in new issue
Block a user