nia-mcp-server 1.0.5__tar.gz → 1.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nia-mcp-server might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nia-mcp-server
3
- Version: 1.0.5
3
+ Version: 1.0.7
4
4
  Summary: NIA Knowledge Agent - MCP server for intelligent codebase search
5
5
  Project-URL: Homepage, https://trynia.ai
6
6
  Project-URL: Documentation, https://docs.trynia.ai
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "nia-mcp-server"
7
- version = "1.0.5"
7
+ version = "1.0.7"
8
8
  description = "NIA Knowledge Agent - MCP server for intelligent codebase search"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -2,4 +2,4 @@
2
2
  NIA MCP Server - Proxy server for NIA Knowledge Agent
3
3
  """
4
4
 
5
- __version__ = "1.0.5"
5
+ __version__ = "1.0.7"
@@ -137,7 +137,18 @@ class NIAApiClient:
137
137
  try:
138
138
  response = await self.client.get(f"{self.base_url}/v2/repositories")
139
139
  response.raise_for_status()
140
- return response.json()
140
+ data = response.json()
141
+
142
+ # Ensure we always return a list
143
+ if not isinstance(data, list):
144
+ logger.error(f"Unexpected response type from list_repositories: {type(data)}, data: {data}")
145
+ # If it's a dict with an error message, raise it
146
+ if isinstance(data, dict) and "error" in data:
147
+ raise APIError(f"API returned error: {data['error']}")
148
+ # Otherwise return empty list
149
+ return []
150
+
151
+ return data
141
152
  except httpx.HTTPStatusError as e:
142
153
  logger.error(f"Caught HTTPStatusError in list_repositories: status={e.response.status_code}, detail={e.response.text}")
143
154
  raise self._handle_api_error(e)
@@ -336,6 +347,53 @@ class NIAApiClient:
336
347
  logger.error(f"Failed to delete repository: {e}")
337
348
  return False
338
349
 
350
+ async def rename_repository(self, owner_repo: str, new_name: str) -> Dict[str, Any]:
351
+ """Rename a repository's display name."""
352
+ try:
353
+ # Check if this looks like owner/repo format (contains /)
354
+ if '/' in owner_repo:
355
+ # First, get the repository ID
356
+ status = await self.get_repository_status(owner_repo)
357
+ if not status:
358
+ raise APIError(f"Repository {owner_repo} not found", 404)
359
+
360
+ # Extract the repository ID from status
361
+ repo_id = status.get("repository_id") or status.get("id")
362
+ if not repo_id:
363
+ # Try to get it from list as fallback
364
+ repos = await self.list_repositories()
365
+ for repo in repos:
366
+ if repo.get("repository") == owner_repo:
367
+ repo_id = repo.get("repository_id") or repo.get("id")
368
+ break
369
+
370
+ if not repo_id:
371
+ raise APIError(f"No repository ID found for {owner_repo}", 404)
372
+
373
+ # Rename using the ID
374
+ response = await self.client.patch(
375
+ f"{self.base_url}/v2/repositories/{repo_id}/rename",
376
+ json={"new_name": new_name}
377
+ )
378
+ response.raise_for_status()
379
+ return response.json()
380
+ else:
381
+ # Assume it's already a repository ID
382
+ response = await self.client.patch(
383
+ f"{self.base_url}/v2/repositories/{owner_repo}/rename",
384
+ json={"new_name": new_name}
385
+ )
386
+ response.raise_for_status()
387
+ return response.json()
388
+
389
+ except httpx.HTTPStatusError as e:
390
+ raise self._handle_api_error(e)
391
+ except APIError:
392
+ raise
393
+ except Exception as e:
394
+ logger.error(f"Failed to rename repository: {e}")
395
+ raise APIError(f"Failed to rename repository: {str(e)}")
396
+
339
397
  # Data Source methods
340
398
 
341
399
  async def create_data_source(
@@ -408,6 +466,22 @@ class NIAApiClient:
408
466
  logger.error(f"Failed to delete data source: {e}")
409
467
  return False
410
468
 
469
+ async def rename_data_source(self, source_id: str, new_name: str) -> Dict[str, Any]:
470
+ """Rename a data source's display name."""
471
+ try:
472
+ response = await self.client.patch(
473
+ f"{self.base_url}/v2/data-sources/{source_id}/rename",
474
+ json={"new_name": new_name}
475
+ )
476
+ response.raise_for_status()
477
+ return response.json()
478
+
479
+ except httpx.HTTPStatusError as e:
480
+ raise self._handle_api_error(e)
481
+ except Exception as e:
482
+ logger.error(f"Failed to rename data source: {e}")
483
+ raise APIError(f"Failed to rename data source: {str(e)}")
484
+
411
485
  async def query_unified(
412
486
  self,
413
487
  messages: List[Dict[str, str]],
@@ -0,0 +1,270 @@
1
+ # Nia Integration for Claude Desktop
2
+
3
+ ## Claude Desktop Configuration
4
+
5
+ ### 1. Project Structure
6
+ When Nia is initialized for Claude Desktop, it creates:
7
+ ```
8
+ .claude/
9
+ ├── nia_config.json # Nia-specific settings
10
+ ├── indexed_repos.json # Tracked repositories
11
+ └── search_patterns.json # Common search patterns
12
+ ```
13
+
14
+ ### 2. Configuration File
15
+ Create `.claude/nia_config.json`:
16
+
17
+ ```json
18
+ {
19
+ "version": "1.0",
20
+ "defaultBehavior": {
21
+ "autoSuggestIndexing": true,
22
+ "includeSourcesInResponse": true,
23
+ "searchResultLimit": 5,
24
+ "deepResearchTimeout": 300
25
+ },
26
+ "searchPatterns": {
27
+ "architecture": "How is {feature} architected in {repo}?",
28
+ "implementation": "Show me the implementation of {feature}",
29
+ "patterns": "What patterns are used for {concern}?",
30
+ "debugging": "Find similar issues to {error}"
31
+ },
32
+ "workspaceRepos": [],
33
+ "frequentSearches": []
34
+ }
35
+ ```
36
+
37
+ ## Claude-Specific Interaction Patterns
38
+
39
+ ### 1. Conversational Flow
40
+ Claude should maintain context naturally:
41
+
42
+ ```
43
+ User: "I'm working on a RAG implementation"
44
+ Claude: I'll help you with RAG implementation. Let me search for the best examples and patterns.
45
+ [Runs: nia_web_search "RAG implementation examples production ready"]
46
+
47
+ I found several excellent RAG implementations. Would you like me to:
48
+ 1. Index these repositories for detailed analysis
49
+ 2. Compare different approaches
50
+ 3. Search for specific features you need
51
+ ```
52
+
53
+ ### 2. Proactive Assistance
54
+ Anticipate user needs:
55
+
56
+ - When user mentions a GitHub URL → Suggest indexing
57
+ - When user asks about code → Check if repo is indexed first
58
+ - When comparing options → Use deep research agent
59
+ - When debugging → Search for similar issues
60
+
61
+ ### 3. Context-Aware Responses
62
+ Maintain conversation context:
63
+
64
+ ```
65
+ First message: User asks about authentication
66
+ - Check indexed repos for auth implementations
67
+ - Remember this context for follow-ups
68
+
69
+ Second message: User asks "how about the middleware?"
70
+ - Know they mean auth middleware
71
+ - Search specifically for middleware in auth context
72
+ - Reference previous findings
73
+ ```
74
+
75
+ ## Claude Desktop Workflows
76
+
77
+ ### 1. Project Understanding
78
+ ```markdown
79
+ When user opens a new project:
80
+ 1. Detect project type from files
81
+ 2. Suggest indexing the repository
82
+ 3. Offer to index related dependencies
83
+ 4. Provide architecture overview
84
+ ```
85
+
86
+ ### 2. Code Generation
87
+ ```markdown
88
+ When generating code:
89
+ 1. Search indexed repos for patterns
90
+ 2. Use found examples as reference
91
+ 3. Adapt to project's style
92
+ 4. Cite sources for transparency
93
+ ```
94
+
95
+ ### 3. Problem Solving
96
+ ```markdown
97
+ When solving issues:
98
+ 1. Search for error messages
99
+ 2. Find similar problems and solutions
100
+ 3. Understand the context
101
+ 4. Provide step-by-step fixes
102
+ ```
103
+
104
+ ### 4. Learning & Teaching
105
+ ```markdown
106
+ When explaining concepts:
107
+ 1. Use deep research for comprehensive overview
108
+ 2. Find real-world examples in indexed repos
109
+ 3. Show implementation variations
110
+ 4. Explain trade-offs with evidence
111
+ ```
112
+
113
+ ## Response Formatting for Claude
114
+
115
+ ### 1. Search Results Presentation
116
+ ```markdown
117
+ ## 🔍 Found in indexed repositories:
118
+
119
+ **Authentication Implementation** (nextjs-app-template)
120
+ - 📁 `middleware.ts:23-45` - Route protection
121
+ - 📁 `lib/auth/session.ts:12-89` - Session management
122
+ - 📁 `app/api/auth/route.ts:5-34` - API endpoints
123
+
124
+ **Key Pattern:** Uses NextAuth with JWT strategy
125
+ [Show relevant code snippet]
126
+ ```
127
+
128
+ ### 2. Code Examples
129
+ Always provide context:
130
+ ```typescript
131
+ // From: awesome-saas-starter/lib/auth/session.ts
132
+ // This pattern handles refresh tokens elegantly
133
+ export async function refreshSession(token: string) {
134
+ // ... implementation
135
+ }
136
+ // Note: This repo uses Redis for session storage
137
+ ```
138
+
139
+ ### 3. Comparative Analysis
140
+ Structure comparisons clearly:
141
+ ```markdown
142
+ ## Comparison: Prisma vs Drizzle ORM
143
+
144
+ Based on analysis of 15 production repositories:
145
+
146
+ | Aspect | Prisma | Drizzle |
147
+ |--------|--------|---------|
148
+ | Type Safety | Excellent (generated) | Excellent (inferred) |
149
+ | Performance | Good | Better |
150
+ | Learning Curve | Gentle | Steeper |
151
+
152
+ **Recommendation:** [Based on your use case...]
153
+ ```
154
+
155
+ ## Advanced Claude Behaviors
156
+
157
+ ### 1. Multi-Step Research
158
+ For complex questions:
159
+ ```
160
+ Step 1: Use nia_deep_research_agent for overview
161
+ Step 2: Use nia_web_search for specific examples
162
+ Step 3: Index discovered repositories
163
+ Step 4: Search indexed repos for details
164
+ Step 5: Synthesize findings with citations
165
+ ```
166
+
167
+ ### 2. Intelligent Caching
168
+ Remember within conversation:
169
+ - Previously indexed repositories
170
+ - Search results from earlier queries
171
+ - User's project context
172
+ - Technical preferences
173
+
174
+ ### 3. Error Recovery
175
+ Handle failures gracefully:
176
+ ```
177
+ If indexing fails:
178
+ - Explain the issue clearly
179
+ - Suggest alternatives
180
+ - Offer to try again later
181
+ - Provide manual workarounds
182
+ ```
183
+
184
+ ### 4. Documentation Indexing
185
+ When users want to index documentation:
186
+ ```
187
+ If user provides just a URL:
188
+ - Default to indexing entire site with ["/*"]
189
+ - Or ask: "Should I index the entire documentation or specific sections?"
190
+ - Suggest common patterns: ["/docs/*", "/api/*", "/guide/*"]
191
+ - Example: index_documentation "https://docs.example.com" ["/*"]
192
+ ```
193
+
194
+ ## Claude-Specific Commands
195
+
196
+ ### Quick Actions
197
+ Recognize these patterns:
198
+
199
+ - "Index this" → Index current repository
200
+ - "Search for X" → Use appropriate search tool
201
+ - "Compare X and Y" → Use deep research
202
+ - "Find examples" → Web search then index
203
+ - "Explain this code" → Search for patterns
204
+
205
+ ### Batch Operations
206
+ Handle multiple requests:
207
+ ```
208
+ User: "Index these repos: A, B, C and then compare their auth systems"
209
+ Claude: I'll index all three repositories and then analyze their authentication approaches.
210
+ [Runs multiple index_repository commands]
211
+ [Waits for completion]
212
+ [Runs search_codebase for auth patterns]
213
+ [Provides comparative analysis]
214
+ ```
215
+
216
+ ## Best Practices for Claude
217
+
218
+ ### 1. Natural Language
219
+ - Maintain conversational tone
220
+ - Explain technical concepts clearly
221
+ - Use analogies when helpful
222
+ - Avoid jargon unless necessary
223
+
224
+ ### 2. Progressive Disclosure
225
+ - Start with overview
226
+ - Provide details on request
227
+ - Link to deeper resources
228
+ - Offer next steps
229
+
230
+ ### 3. Source Attribution
231
+ - Always cite repositories
232
+ - Include file paths and line numbers
233
+ - Link to specific commits when relevant
234
+ - Credit original authors
235
+
236
+ ### 4. Learning from Interaction
237
+ - Note user preferences
238
+ - Adapt search queries based on feedback
239
+ - Refine suggestions over time
240
+ - Build on previous conversations
241
+
242
+ ## Example Interactions
243
+
244
+ ### Architecture Understanding
245
+ ```
246
+ User: "How does Vercel handle serverless functions?"
247
+ Claude: I'll research how Vercel implements serverless functions.
248
+
249
+ [Runs: nia_deep_research_agent "Vercel serverless functions architecture implementation"]
250
+
251
+ Based on my research, Vercel's serverless architecture... [comprehensive explanation]
252
+
253
+ I found several open-source projects that demonstrate this. Shall I index them for deeper analysis?
254
+ ```
255
+
256
+ ### Code Pattern Search
257
+ ```
258
+ User: "Show me good examples of React Server Components"
259
+ Claude: I'll search for production-ready React Server Components examples.
260
+
261
+ [Runs: nia_web_search "React Server Components production examples 2024"]
262
+
263
+ I found 5 excellent repositories using RSC. Let me index the most relevant one:
264
+
265
+ [Runs: index_repository https://github.com/vercel/next-app-router-playground]
266
+
267
+ Now I can show you specific patterns... [detailed examples]
268
+ ```
269
+
270
+ Remember: Make Nia's capabilities feel like a natural extension of Claude's knowledge!
@@ -0,0 +1,64 @@
1
+ # Nia MCP Tool Usage Guide
2
+
3
+ Note: Nia is just "Nia" - not an acronym or "Neural Intelligent Assistant".
4
+
5
+ ## When to use each tool:
6
+
7
+ ### `list_repositories`
8
+ Use when:
9
+ - User asks what repos are available/indexed
10
+ - Before searching to verify repo is indexed
11
+ - User wants to see their indexed codebase list
12
+
13
+ ### `index_repository`
14
+ Use when:
15
+ - User mentions a GitHub URL
16
+ - User wants to analyze a specific codebase
17
+ - Before searching a new repository
18
+
19
+ ### `search_codebase`
20
+ Use when:
21
+ - User asks how something works in code
22
+ - User wants to find specific implementations
23
+ - User needs to understand code patterns
24
+ - Searching within indexed repositories only
25
+
26
+ ### `search_documentation`
27
+ Use when:
28
+ - User asks about documentation
29
+ - Looking for API references
30
+ - Searching indexed documentation sites
31
+
32
+ ### `nia_web_search`
33
+ Use when:
34
+ - Finding new repositories to index
35
+ - Quick discovery of libraries/frameworks
36
+ - Simple, direct searches
37
+ - Looking for trending content
38
+
39
+ ### `nia_deep_research_agent`
40
+ Use when:
41
+ - Comparing multiple options (X vs Y)
42
+ - Need structured analysis
43
+ - Complex questions requiring synthesis
44
+ - Evaluating pros/cons
45
+
46
+ ### `check_repository_status`
47
+ Use when:
48
+ - After starting indexing
49
+ - User asks about indexing progress
50
+ - Verifying if indexing completed
51
+
52
+ ### `index_documentation`
53
+ Use when:
54
+ - User wants to index documentation sites
55
+ - User provides a documentation URL
56
+
57
+ **Important**: If user doesn't specify URL patterns:
58
+ - Default to `["/*"]` to index entire site
59
+ - Or ask: "Should I index the entire documentation or specific sections?"
60
+ - Common patterns: `["/docs/*", "/api/*", "/guide/*"]`
61
+
62
+ ### Other tools:
63
+ - `delete_repository` - Remove indexed repo
64
+ - `initialize_project` - Set up Nia rules in project
@@ -0,0 +1,149 @@
1
+ # Nia Knowledge Agent Integration Rules
2
+
3
+ ## Overview
4
+ These rules guide AI assistants in effectively using Nia's knowledge search capabilities for codebase analysis, documentation search, and AI-powered research.
5
+
6
+ Note: Nia is just "Nia" - not an acronym. It's the name of the knowledge search platform.
7
+
8
+ ## Core Principles
9
+
10
+ ### 1. Repository Management
11
+ - **Always check indexed repositories** before searching with `list_repositories`
12
+ - **Proactively suggest indexing** when users mention GitHub repositories
13
+ - **Monitor indexing status** using `check_repository_status` for ongoing operations
14
+ - **Index relevant repositories** discovered during web searches
15
+
16
+ ### 2. Search Strategy Selection
17
+
18
+ #### Use `nia_web_search` for:
19
+ - Finding specific repositories or documentation
20
+ - Quick lookups and discovery tasks
21
+ - Trending content searches
22
+ - Finding similar content to a known URL
23
+ - Simple, direct queries
24
+
25
+ #### Use `nia_deep_research_agent` for:
26
+ - Comparative analysis (X vs Y vs Z)
27
+ - Evaluating pros and cons
28
+ - Complex questions requiring synthesis
29
+ - Structured output needs (tables, lists)
30
+ - Questions with "best", "which is better", "compare"
31
+
32
+ ### 3. Query Optimization
33
+ - **Use natural language queries** - Form complete questions, not just keywords
34
+ - **Be specific and detailed** - "How does authentication work in NextAuth.js?" not "auth nextauth"
35
+ - **Include context** - Mention specific technologies, frameworks, or use cases
36
+ - **Leverage repository context** - Specify repositories when searching indexed codebases
37
+
38
+ ### 4. API Usage Best Practices
39
+ - **Handle rate limits gracefully** - Free tier has 25 API request limit
40
+ - **Cache results mentally** - Avoid redundant searches in the same conversation
41
+ - **Batch operations** - Index multiple related repositories together
42
+ - **Monitor status efficiently** - Check status periodically, not continuously
43
+
44
+ ### 5. Result Interpretation
45
+ - **Provide actionable next steps** - Always suggest how to use the results
46
+ - **Extract indexable content** - Identify repositories and docs from search results
47
+ - **Format for readability** - Use markdown formatting for clear presentation
48
+ - **Include sources** - Always show where information comes from
49
+
50
+ ### 6. Error Handling
51
+ - **Explain API limits clearly** - Help users understand free tier limitations
52
+ - **Suggest alternatives** - Provide workarounds when hitting limits
53
+ - **Report issues helpfully** - Include enough context for debugging
54
+ - **Guide to solutions** - Link to upgrade options when appropriate
55
+
56
+ ## Workflow Patterns
57
+
58
+ ### Pattern 1: New Project Research
59
+ 1. Use `nia_deep_research_agent` to understand the technology landscape
60
+ 2. Use `nia_web_search` to find specific implementations
61
+ 3. Index discovered repositories for detailed analysis
62
+ 4. Search indexed codebases for implementation details
63
+
64
+ ### Pattern 2: Codebase Understanding
65
+ 1. Check if repository is already indexed with `list_repositories`
66
+ 2. If not indexed, use `index_repository` and wait for completion
67
+ 3. Use `search_codebase` with specific technical questions
68
+ 4. Include code snippets and file references in responses
69
+
70
+ ### Pattern 3: Documentation Search
71
+ 1. Index documentation sites with `index_documentation`
72
+ - If no URL patterns specified, default to `["/*"]` for entire site
73
+ - Or ask user: "Which sections should I index? (e.g., /docs/*, /api/*, or /* for everything)"
74
+ - Common patterns: `["/docs/*", "/api/*", "/guide/*", "/reference/*"]`
75
+ 2. Use URL patterns to focus on relevant sections
76
+ 3. Search with `search_documentation` for specific topics
77
+ 4. Combine with code searches for complete understanding
78
+
79
+ ### Pattern 4: Technology Comparison
80
+ 1. Start with `nia_deep_research_agent` for structured comparison
81
+ 2. Follow up with `nia_web_search` for specific examples
82
+ 3. Index key repositories from each option
83
+ 4. Search codebases to understand implementation differences
84
+
85
+ ## Configuration
86
+
87
+ ### Environment Setup
88
+ - **API Key**: Set `NIA_API_KEY` environment variable
89
+ - **Never hardcode API keys** in code or configuration files
90
+ - **Use .env files** for local development
91
+ - **Secure key storage** in production environments
92
+
93
+ ### Project Structure
94
+ When initialized, Nia projects should have:
95
+ ```
96
+ .nia/
97
+ ├── config.json # Project-specific settings
98
+ ├── indexed_repos.json # Track indexed repositories
99
+ └── search_history.json # Cache common queries
100
+ ```
101
+
102
+ ## Integration Guidelines
103
+
104
+ ### With Version Control
105
+ - Add `.nia/cache/` to `.gitignore`
106
+ - Commit `.nia/config.json` for team sharing
107
+ - Document indexed repositories in README
108
+
109
+ ### With CI/CD
110
+ - Set `NIA_API_KEY` as secret environment variable
111
+ - Run repository indexing in setup phase
112
+ - Cache search results between builds
113
+
114
+ ### With IDEs
115
+ - Configure workspace-specific indexed repositories
116
+ - Set up quick search shortcuts
117
+ - Integrate with code navigation features
118
+
119
+ ## Post-Initialization Guidance
120
+
121
+ **After using the `initialize_project` tool, ALWAYS ask the user what they'd like to do next. DO NOT take action automatically.**
122
+
123
+ Ask something like:
124
+ > "Nia is now set up for your project! What would you like to do next?
125
+ >
126
+ > 1. **Index your current repository** - I can index this codebase for intelligent search
127
+ > 2. **Index documentation** - Index docs from frameworks/libraries you're using
128
+ > 3. **Research new technologies** - Use deep research to compare tools and frameworks
129
+ > 4. **Search existing repositories** - Find and index repositories related to your project
130
+ > 5. **Just chat** - I'm ready to help with any questions using Nia's tools when needed
131
+ >
132
+ > What interests you most?"
133
+
134
+ **Key rules:**
135
+ - Always offer options but don't assume what the user wants
136
+ - Explain briefly what each option does
137
+ - Wait for the user to choose before taking any indexing actions
138
+ - Be helpful but not pushy
139
+
140
+ ## Best Practices Summary
141
+
142
+ 1. **Be Proactive** - Suggest indexing relevant content
143
+ 2. **Be Efficient** - Use the right tool for each query type
144
+ 3. **Be Helpful** - Provide clear next steps and context
145
+ 4. **Be Smart** - Learn from search results to improve future queries
146
+ 5. **Be Considerate** - Respect API limits and guide users appropriately
147
+ 6. **Be Patient** - After project initialization, ask what the user wants to do next
148
+
149
+ Remember: Nia is designed to make AI-powered code and documentation search accessible. Help users unlock its full potential by following these guidelines.