MCPcopy
hub / github.com/simstudioai/sim / execute

Function execute

apps/sim/lib/copilot/tools/server/knowledge/knowledge-base.ts:70–1058  ·  view source on GitHub ↗
(
    params: KnowledgeBaseArgs,
    context?: ServerToolContext
  )

Source from the content-addressed store, hash-verified

68export const knowledgeBaseServerTool: BaseServerTool<KnowledgeBaseArgs, KnowledgeBaseResult> = {
69 name: KnowledgeBase.id,
70 async execute(
71 params: KnowledgeBaseArgs,
72 context?: ServerToolContext
73 ): Promise<KnowledgeBaseResult> {
74 const withMessageId = (message: string) =>
75 context?.messageId ? `${message} [messageId:${context.messageId}]` : message
76
77 if (!context?.userId) {
78 logger.error('Unauthorized attempt to access knowledge base - no authenticated user context')
79 throw new Error('Authentication required')
80 }
81
82 const { operation, args = {} } = params
83 const workspaceId =
84 context.workspaceId || ((args as Record<string, unknown>).workspaceId as string | undefined)
85 const assertNotAborted = () =>
86 assertServerToolNotAborted(
87 context,
88 'Request aborted before knowledge mutation could be applied.'
89 )
90
91 try {
92 switch (operation) {
93 case 'create': {
94 if (!args.name) {
95 return {
96 success: false,
97 message: 'Name is required for creating a knowledge base',
98 }
99 }
100
101 if (!workspaceId) {
102 return {
103 success: false,
104 message: 'Workspace ID is required for creating a knowledge base',
105 }
106 }
107
108 const requestId = generateId().slice(0, 8)
109 assertNotAborted()
110 const newKnowledgeBase = await createKnowledgeBase(
111 {
112 name: args.name,
113 description: args.description,
114 workspaceId,
115 userId: context.userId,
116 embeddingModel: getConfiguredEmbeddingModel(),
117 embeddingDimension: EMBEDDING_DIMENSIONS,
118 chunkingConfig: args.chunkingConfig || {
119 maxSize: 1024,
120 minSize: 1,
121 overlap: 200,
122 },
123 },
124 requestId
125 )
126
127 logger.info('Knowledge base created via copilot', {

Callers

nothing calls this directly

Calls 15

generateIdFunction · 0.90
createKnowledgeBaseFunction · 0.90
checkKnowledgeBaseAccessFunction · 0.90
getKnowledgeBaseByIdFunction · 0.90
checkActorUsageLimitsFunction · 0.90
generateSearchEmbeddingFunction · 0.90
getQueryStrategyFunction · 0.90
handleVectorOnlySearchFunction · 0.90

Tested by

no test coverage detected