feat(chat): MCP stdio 工具接入
- McpServer:启动进程、initialize、tools/list、tools/call - McpManager:多服务器、工具名冲突处理、OpenAI function 定义 - ChatClient:请求携带 tools,流式累积 tool_calls,结束后交回上层 - ChatWindow:工具调用循环(最多 5 轮)、scaffold 消息、设置里的 MCP JSON 编辑 - 无头自测 gxde-ai-see-mcptest + tests/mcp/test_server.py 验证通过
This commit is contained in:
+13
-1
@@ -3,6 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
@@ -14,6 +15,13 @@ struct ChatMessage
|
||||
QString content;
|
||||
};
|
||||
|
||||
struct ToolCall
|
||||
{
|
||||
QString id;
|
||||
QString name;
|
||||
QString arguments;
|
||||
};
|
||||
|
||||
/**
|
||||
* Minimal client for the DeepSeek (OpenAI compatible) chat API.
|
||||
*
|
||||
@@ -28,7 +36,8 @@ public:
|
||||
explicit ChatClient(QObject *parent = nullptr);
|
||||
|
||||
bool busy() const { return m_reply != nullptr; }
|
||||
void send(const QVector<ChatMessage> &messages);
|
||||
void setTools(const QJsonArray &tools);
|
||||
void send(const QVector<ChatMessage> &messages, const QJsonArray &extraMessages = QJsonArray());
|
||||
void sendOnce(const QVector<ChatMessage> &messages);
|
||||
void cancel();
|
||||
|
||||
@@ -38,6 +47,7 @@ signals:
|
||||
void failed(const QString &error);
|
||||
void onceFinished(const QString &text);
|
||||
void onceFailed(const QString &error);
|
||||
void toolCallsReady(const QVector<ToolCall> &calls);
|
||||
|
||||
private:
|
||||
void handleReadyRead();
|
||||
@@ -48,6 +58,8 @@ private:
|
||||
class QNetworkReply *m_reply = nullptr;
|
||||
class QNetworkReply *m_onceReply = nullptr;
|
||||
QByteArray m_buffer;
|
||||
QJsonArray m_tools;
|
||||
QVector<ToolCall> m_toolCalls;
|
||||
QString m_fullText;
|
||||
bool m_done = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user