Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions data/schemas/20260312010200_corpus.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

ALTER TABLE qa_corpus_document RENAME TO corpus_document;
ALTER TABLE qa_corpus_vector_400 RENAME TO corpus_vector_400;
8 changes: 4 additions & 4 deletions docs/cob.yaml → docs/corpus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ depends:
comm: github.com/cupogo/andvari/models/comm
oid: github.com/cupogo/andvari/models/oid

gename: cob
gename: corpus
modelpkg: corpus

models:
- name: Document
comment: '文档 语料库'
tableTag: 'qa_corpus_document,alias:cd'
tableTag: 'corpus_document,alias:cd'
fields:
- name: comm.DefaultModel
- comment: 主标题 名称
Expand Down Expand Up @@ -41,7 +41,7 @@ models:

- name: DocVector
comment: '文档向量 400=1024, 600=1536'
tableTag: 'qa_corpus_vector_400,alias:cv'
tableTag: 'corpus_vector_400,alias:cv'
fields:
- name: comm.DefaultModel
- comment: 文档编号
Expand Down Expand Up @@ -93,7 +93,7 @@ models:
# export2: true

- name: ChatLog
comment: '聊天日志'
comment: '聊天日志 Deprecated'
tableTag: 'qa_chat_log,alias:cl'
fields:
- name: comm.DefaultModel
Expand Down
25 changes: 25 additions & 0 deletions docs/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

```json
fetch('/api/m/mcp/servers', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'webpawm',
transType: 'streamable',
url: 'http://localhost:8087/mcp',
remark: '用于搜索'
})
})
.then(r => r.json())
.then(console.log);


fetch('/api/m/mcp/servers/fi-54ionou2hq0w/activate', {
method: 'PUT'
})
.then(r => r.json())
.then(console.log);

```json
33 changes: 26 additions & 7 deletions docs/mcps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ enums:
textMarshaler: true
textUnmarshaler: true

- comment: 状态
- comment: 状态 用于表示连接
name: Status
start: 0
type: int8
values:
- label: 已停止
suffix: Stopped
- label: 运行中
suffix: Running
- label: 断开 初始默认
suffix: Disconnected
- label: 连接中
suffix: Connecting
- label: 已连接
suffix: Connected
stringer: true
decodable: true
textMarshaler: true
Expand All @@ -46,7 +48,7 @@ models:

- name: Server
comment: '服务器'
tableTag: 'qa_mcp_server,alias:s'
tableTag: 'mcp_server,alias:ms'
fields:
- type: comm.DefaultModel
- comment: 名称
Expand All @@ -71,7 +73,13 @@ models:
type: string
tags: {bson: 'url', json: 'url', pg: ',notnull'}
isset: true
- comment: '状态'
- comment: '是否激活'
name: IsActive
type: bool
tags: {bson: 'isActive', json: 'isActive', pg: ',notnull'}
isset: true
query: 'equal'
- comment: '连接状态'
name: Status
type: Status
tags: {bson: 'status', json: 'status', pg: ',notnull,type:smallint'}
Expand All @@ -92,3 +100,14 @@ stores:
siname: MCP
hods:
- { name: Server, type: LGCUD }


webcode: chi
webapi:
formTag: form
pkg: api
needAuth: true
needPerm: true
uris:
- model: Server
prefix: '/api/mcp'
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func embeddingDocVector(cc *cli.Context) error {
spec := &stores.CobDocumentSpec{}
spec.Limit = 90
spec.Sort = "id"
return stores.Sgt().Qa().EmbeddingDocVector(ctx, spec)
return stores.Sgt().KB().EmbeddingDocVector(ctx, spec)
// return nil
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/models/corpus/cob_gen.go → pkg/models/corpus/corpus_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (

// consts of Document 文档
const (
DocumentTable = "qa_corpus_document"
DocumentTable = "corpus_document"
DocumentAlias = "cd"
DocumentLabel = "document"
DocumentTypID = "corpusDocument"
)

// Document 文档 语料库
type Document struct {
comm.BaseModel `bun:"table:qa_corpus_document,alias:cd" json:"-"`
comm.BaseModel `bun:"table:corpus_document,alias:cd" json:"-"`

comm.DefaultModel

Expand Down Expand Up @@ -103,15 +103,15 @@ func (in *DocumentSet) MetaAddKVs(args ...any) *DocumentSet {

// consts of DocVector 文档向量
const (
DocVectorTable = "qa_corpus_vector_400"
DocVectorTable = "corpus_vector_400"
DocVectorAlias = "cv"
DocVectorLabel = "docVector"
DocVectorTypID = "corpusDocVector"
)

// DocVector 文档向量 400=1024, 600=1536
type DocVector struct {
comm.BaseModel `bun:"table:qa_corpus_vector_400,alias:cv" json:"-"`
comm.BaseModel `bun:"table:corpus_vector_400,alias:cv" json:"-"`

comm.DefaultModel

Expand Down Expand Up @@ -218,7 +218,7 @@ const (
ChatLogTypID = "corpusChatLog"
)

// ChatLog 聊天日志
// ChatLog 聊天日志 Deprecated
type ChatLog struct {
comm.BaseModel `bun:"table:qa_chat_log,alias:cl" json:"-"`

Expand Down
File renamed without changes.
File renamed without changes.
63 changes: 39 additions & 24 deletions pkg/models/mcps/mcps_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,23 @@ func (z TransType) MarshalText() ([]byte, error) {
return []byte(z.String()), nil
}

// 状态
// 状态 用于表示连接
type Status int8

const (
StatusStopped Status = 0 + iota // 0 已停止
StatusRunning // 1 运行中
StatusDisconnected Status = 0 + iota // 0 断开 初始默认
StatusConnecting // 1 连接中
StatusConnected // 2 已连接
)

func (z *Status) Decode(s string) error {
switch s {
case "0", "stopped", "Stopped":
*z = StatusStopped
case "1", "running", "Running":
*z = StatusRunning
case "0", "disconnected", "Disconnected":
*z = StatusDisconnected
case "1", "connecting", "Connecting":
*z = StatusConnecting
case "2", "connected", "Connected":
*z = StatusConnected
default:
return fmt.Errorf("invalid status: %q", s)
}
Expand All @@ -79,10 +82,12 @@ func (z *Status) UnmarshalText(b []byte) error {
}
func (z Status) String() string {
switch z {
case StatusStopped:
return "stopped"
case StatusRunning:
return "running"
case StatusDisconnected:
return "disconnected"
case StatusConnecting:
return "connecting"
case StatusConnected:
return "connected"
default:
return fmt.Sprintf("status %d", int8(z))
}
Expand All @@ -93,15 +98,15 @@ func (z Status) MarshalText() ([]byte, error) {

// consts of Server 服务器
const (
ServerTable = "qa_mcp_server"
ServerAlias = "s"
ServerTable = "mcp_server"
ServerAlias = "ms"
ServerLabel = "server"
ServerTypID = "mcpsServer"
)

// Server 服务器
type Server struct {
comm.BaseModel `bun:"table:qa_mcp_server,alias:s" json:"-"`
comm.BaseModel `bun:"table:mcp_server,alias:ms" json:"-"`

comm.DefaultModel

Expand All @@ -123,12 +128,15 @@ type ServerBasic struct {
Command string `bson:"command" bun:",notnull" extensions:"x-order=C" form:"command" json:"command" pg:",notnull"`
// 完整网址 仅对 TransType 为 SSE 或 HTTP 时有效
URL string `bson:"url" bun:",notnull" extensions:"x-order=D" form:"url" json:"url" pg:",notnull"`
// 状态
// * `stopped` - 已停止
// * `running` - 运行中
Status Status `bson:"status" bun:",notnull,type:smallint" enums:"stopped,running" extensions:"x-order=E" form:"status" json:"status" pg:",notnull,type:smallint" swaggertype:"string"`
// 是否激活
IsActive bool `bson:"isActive" bun:",notnull" extensions:"x-order=E" form:"isActive" json:"isActive" pg:",notnull"`
// 连接状态
// * `disconnected` - 断开
// * `connecting` - 连接中
// * `connected` - 已连接
Status Status `bson:"status" bun:",notnull,type:smallint" enums:"disconnected,connecting,connected" extensions:"x-order=F" form:"status" json:"status" pg:",notnull,type:smallint" swaggertype:"string"`
// 备注
Remark string `bson:"remark" bun:",notnull" extensions:"x-order=F" form:"remark" json:"remark" pg:",notnull"`
Remark string `bson:"remark" bun:",notnull" extensions:"x-order=G" form:"remark" json:"remark" pg:",notnull"`
// for meta update
MetaDiff *comm.MetaDiff `bson:"-" bun:"-" json:"metaUp,omitempty" pg:"-" swaggerignore:"true"`
} // @name mcpsServerBasic
Expand Down Expand Up @@ -173,12 +181,15 @@ type ServerSet struct {
Command *string `extensions:"x-order=C" json:"command"`
// 完整网址 仅对 TransType 为 SSE 或 HTTP 时有效
URL *string `extensions:"x-order=D" json:"url"`
// 状态
// * `stopped` - 已停止
// * `running` - 运行中
Status *Status `enums:"stopped,running" extensions:"x-order=E" json:"status" swaggertype:"string"`
// 是否激活
IsActive *bool `extensions:"x-order=E" json:"isActive"`
// 连接状态
// * `disconnected` - 断开
// * `connecting` - 连接中
// * `connected` - 已连接
Status *Status `enums:"disconnected,connecting,connected" extensions:"x-order=F" json:"status" swaggertype:"string"`
// 备注
Remark *string `extensions:"x-order=F" json:"remark"`
Remark *string `extensions:"x-order=G" json:"remark"`
// for meta update
MetaDiff *comm.MetaDiff `json:"metaUp,omitempty" swaggerignore:"true"`
} // @name mcpsServerSet
Expand All @@ -200,6 +211,10 @@ func (z *Server) SetWith(o ServerSet) {
z.LogChangeValue("url", z.URL, o.URL)
z.URL = *o.URL
}
if o.IsActive != nil && z.IsActive != *o.IsActive {
z.LogChangeValue("is_active", z.IsActive, o.IsActive)
z.IsActive = *o.IsActive
}
if o.Status != nil && z.Status != *o.Status {
z.LogChangeValue("status", z.Status, o.Status)
z.Status = *o.Status
Expand Down
6 changes: 6 additions & 0 deletions pkg/models/mcps/mcps_x.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package mcps

// IsRemote 判断是否为远程传输类型(SSE 或 Streamable)
func (t TransType) IsRemote() bool {
return t == TransTypeSSE || t == TransTypeStreamable
}
3 changes: 3 additions & 0 deletions pkg/models/mcps/tool.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package mcps

import (
"context"
"encoding/json"
"fmt"
"math"
"strings"
)

type Invoker func(ctx context.Context, params map[string]any) (map[string]any, error)

// ToolDescriptor 是工具的描述符,用于 MCP 工具列表
type ToolDescriptor struct {
Name string `json:"name"`
Expand Down
Loading
Loading