Skip to content

Commit 8fbf594

Browse files
authored
Merge pull request #46 from jgwill/copilot/update-files-in-coaiapy-mcp
Implement coaiapy-mcp package with library import approach (Phase 1 complete)
2 parents 7b0eb6f + 4b71e70 commit 8fbf594

38 files changed

+5437
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,4 @@ out.scorelist.txt
184184

185185
#llms
186186

187+
.gemini
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Comment Support Implementation Summary
2+
3+
## Overview
4+
Added comprehensive comment support to both `coaiapy` and `coaiapy-mcp` packages, enabling full access to Langfuse comment functionality for traces, observations, sessions, and prompts.
5+
6+
## Changes Made
7+
8+
### 1. Enhanced coaiapy/cofuse.py (coaiapy:289-362)
9+
10+
#### Modified Functions:
11+
12+
**`get_comments()`** - Enhanced with filtering support
13+
- **New Parameters:**
14+
- `object_type`: Filter by object type (trace, observation, session, prompt)
15+
- `object_id`: Filter by specific object ID (requires object_type)
16+
- `author_user_id`: Filter by author user ID
17+
- `page`: Page number (starts at 1, default=1)
18+
- `limit`: Items per page (default=50)
19+
- **Returns:** JSON response with filtered comments
20+
21+
**`get_comment_by_id(comment_id)`** - New function
22+
- **Purpose:** Retrieve specific comment by its unique ID
23+
- **Parameters:** `comment_id` (required)
24+
- **Returns:** JSON response with comment data
25+
26+
**`post_comment(text, object_type, object_id)`** - Enhanced with object attachment
27+
- **New Parameters:**
28+
- `object_type`: Type of object to attach comment to
29+
- `object_id`: ID of the object to attach comment to
30+
- **Returns:** JSON response with created comment data
31+
32+
### 2. Added MCP Tools (coaiapy-mcp/tools.py:521-689)
33+
34+
#### New Tool Functions:
35+
36+
**`coaia_fuse_comments_list()`** - List/filter comments
37+
- Wraps `get_comments()` with MCP-compatible error handling
38+
- Supports all filtering parameters
39+
- Returns structured JSON response
40+
41+
**`coaia_fuse_comments_get(comment_id)`** - Get specific comment
42+
- Wraps `get_comment_by_id()` with MCP error handling
43+
- Returns parsed JSON or raw string with success status
44+
45+
**`coaia_fuse_comments_create(text, object_type, object_id)`** - Create comment
46+
- Wraps `post_comment()` with MCP error handling
47+
- Supports attaching to traces, observations, sessions, prompts
48+
49+
#### Tool Registry Updates:
50+
- Added 3 new tools to `TOOLS` dict
51+
- Updated `__all__` export list
52+
53+
### 3. MCP Server Registration (coaiapy-mcp/server.py:223-263)
54+
55+
#### New Tool Definitions:
56+
57+
**`coaia_fuse_comments_list`**
58+
```json
59+
{
60+
"name": "coaia_fuse_comments_list",
61+
"description": "List comments with optional filtering by object type/ID or author",
62+
"inputSchema": {
63+
"object_type": "string",
64+
"object_id": "string",
65+
"author_user_id": "string",
66+
"page": "integer (default: 1)",
67+
"limit": "integer (default: 50)"
68+
}
69+
}
70+
```
71+
72+
**`coaia_fuse_comments_get`**
73+
```json
74+
{
75+
"name": "coaia_fuse_comments_get",
76+
"description": "Get a specific comment by ID",
77+
"inputSchema": {
78+
"comment_id": "string (required)"
79+
}
80+
}
81+
```
82+
83+
**`coaia_fuse_comments_create`**
84+
```json
85+
{
86+
"name": "coaia_fuse_comments_create",
87+
"description": "Create a comment attached to an object",
88+
"inputSchema": {
89+
"text": "string (required)",
90+
"object_type": "string",
91+
"object_id": "string"
92+
}
93+
}
94+
```
95+
96+
## API Compliance
97+
98+
All implementations match Langfuse OpenAPI spec (references/openapi.yml:517-693):
99+
100+
`GET /api/public/comments` - List with filters (objectType, objectId, authorUserId, page, limit)
101+
`GET /api/public/comments/{commentId}` - Get by ID
102+
`POST /api/public/comments` - Create with object attachment
103+
104+
## Usage Examples
105+
106+
### Using coaiapy directly:
107+
```python
108+
from coaiapy.cofuse import get_comments, get_comment_by_id, post_comment
109+
110+
# List all comments for a trace
111+
comments = get_comments(object_type="trace", object_id="trace-123")
112+
113+
# Get specific comment
114+
comment = get_comment_by_id("comment-456")
115+
116+
# Create comment on observation
117+
new_comment = post_comment(
118+
text="Great performance!",
119+
object_type="observation",
120+
object_id="obs-789"
121+
)
122+
```
123+
124+
### Using MCP tools:
125+
```python
126+
# Via Claude Code or MCP-compatible client
127+
await mcp__coaiapy__coaia_fuse_comments_list({
128+
"object_type": "trace",
129+
"object_id": "trace-123"
130+
})
131+
132+
await mcp__coaiapy__coaia_fuse_comments_get({
133+
"comment_id": "comment-456"
134+
})
135+
136+
await mcp__coaiapy__coaia_fuse_comments_create({
137+
"text": "Analysis complete",
138+
"object_type": "trace",
139+
"object_id": "trace-123"
140+
})
141+
```
142+
143+
## Testing
144+
145+
All comment functionality is now exposed through:
146+
1. Direct Python imports from `coaiapy.cofuse`
147+
2. MCP tools via `coaiapy-mcp` server
148+
3. Claude Code integration (if MCP server configured)
149+
150+
## Files Modified
151+
152+
1. `/src/coaiapy/coaiapy/cofuse.py` - Enhanced comment functions (lines 289-362)
153+
2. `/src/coaiapy/coaiapy-mcp/coaiapy_mcp/tools.py` - Added MCP tool wrappers (lines 20-32, 521-741)
154+
3. `/src/coaiapy/coaiapy-mcp/coaiapy_mcp/server.py` - Registered MCP tools (lines 223-263)
155+
156+
## Next Steps
157+
158+
- ✅ Test comment listing with filters
159+
- ✅ Test comment creation on traces/observations
160+
- ✅ Test comment retrieval by ID
161+
- ✅ Verify MCP tool exposure in Claude Code
162+
- 🔄 Add comment functionality to CLI (optional enhancement)
163+
- 🔄 Add comment support to pipeline templates (optional enhancement)

RESUME_issue_49__251030.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
claude --resume efbd2ebf-389c-44b6-9325-b73a97857979 --mcp-config /src/.mcp.coaiapy-dev.json

0 commit comments

Comments
 (0)