mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat: mcp (#31)
* feat: add mcp connections table and related crud api * feat: mcp-stdio api
This commit is contained in:
@@ -12,6 +12,7 @@ DROP TABLE IF EXISTS bot_channel_configs;
|
||||
DROP TABLE IF EXISTS user_channel_bindings;
|
||||
DROP TABLE IF EXISTS history;
|
||||
DROP TABLE IF EXISTS conversations;
|
||||
DROP TABLE IF EXISTS mcp_connections;
|
||||
DROP TABLE IF EXISTS bot_model_configs;
|
||||
DROP TABLE IF EXISTS bot_settings;
|
||||
DROP TABLE IF EXISTS bot_members;
|
||||
|
||||
@@ -106,6 +106,21 @@ CREATE TABLE IF NOT EXISTS bot_model_configs (
|
||||
memory_model_id UUID REFERENCES models(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS mcp_connections (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
bot_id UUID NOT NULL REFERENCES bots(id) ON DELETE CASCADE,
|
||||
name TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
config JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
is_active BOOLEAN NOT NULL DEFAULT true,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
CONSTRAINT mcp_connections_type_check CHECK (type IN ('stdio', 'http', 'sse')),
|
||||
CONSTRAINT mcp_connections_unique UNIQUE (bot_id, name)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_mcp_connections_bot_id ON mcp_connections(bot_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS conversations (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
bot_id UUID NOT NULL REFERENCES bots(id) ON DELETE CASCADE,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
-- name: GetMCPConnectionByID :one
|
||||
SELECT id, bot_id, name, type, config, is_active, created_at, updated_at
|
||||
FROM mcp_connections
|
||||
WHERE bot_id = $1 AND id = $2
|
||||
LIMIT 1;
|
||||
|
||||
-- name: ListMCPConnectionsByBotID :many
|
||||
SELECT id, bot_id, name, type, config, is_active, created_at, updated_at
|
||||
FROM mcp_connections
|
||||
WHERE bot_id = $1
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: CreateMCPConnection :one
|
||||
INSERT INTO mcp_connections (bot_id, name, type, config, is_active)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, bot_id, name, type, config, is_active, created_at, updated_at;
|
||||
|
||||
-- name: UpdateMCPConnection :one
|
||||
UPDATE mcp_connections
|
||||
SET name = $3,
|
||||
type = $4,
|
||||
config = $5,
|
||||
is_active = $6,
|
||||
updated_at = now()
|
||||
WHERE bot_id = $1 AND id = $2
|
||||
RETURNING id, bot_id, name, type, config, is_active, created_at, updated_at;
|
||||
|
||||
-- name: DeleteMCPConnection :exec
|
||||
DELETE FROM mcp_connections
|
||||
WHERE bot_id = $1 AND id = $2;
|
||||
Reference in New Issue
Block a user