feat: Add task-mcp server for task management via MCP
Implements 10 MCP tools for task management: - CRUD: task_add, task_list, task_show, task_close, task_update - Search: task_similar (pgvector), task_context - Relations: task_link, task_checklist_add, task_checklist_toggle Uses PostgreSQL with pgvector for semantic search via LiteLLM embeddings. Connects via SSH tunnel to docker-host:5435. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
58
src/embeddings.ts
Normal file
58
src/embeddings.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
// Embeddings via LiteLLM API
|
||||
|
||||
const LLM_API_URL = process.env.LLM_API_URL || 'https://llm.agiliton.cloud';
|
||||
const LLM_API_KEY = process.env.LLM_API_KEY || '';
|
||||
|
||||
interface EmbeddingResponse {
|
||||
data: Array<{
|
||||
embedding: number[];
|
||||
index: number;
|
||||
}>;
|
||||
model: string;
|
||||
usage: {
|
||||
prompt_tokens: number;
|
||||
total_tokens: number;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate embedding for text using LiteLLM API
|
||||
*/
|
||||
export async function getEmbedding(text: string): Promise<number[] | null> {
|
||||
if (!LLM_API_KEY) {
|
||||
console.error('LLM_API_KEY not set, skipping embedding');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${LLM_API_URL}/v1/embeddings`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${LLM_API_KEY}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: 'text-embedding-ada-002',
|
||||
input: text,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Embedding API error:', response.status, await response.text());
|
||||
return null;
|
||||
}
|
||||
|
||||
const data = await response.json() as EmbeddingResponse;
|
||||
return data.data?.[0]?.embedding || null;
|
||||
} catch (error) {
|
||||
console.error('Embedding generation failed:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format embedding array for PostgreSQL vector type
|
||||
*/
|
||||
export function formatEmbedding(embedding: number[]): string {
|
||||
return `[${embedding.join(',')}]`;
|
||||
}
|
||||
Reference in New Issue
Block a user