Skip to content
Open
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 .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ MILVUS_ADDRESS=your-zilliz-cloud-public-endpoint
# https://github.com/zilliztech/claude-context/blob/master/assets/signup_and_get_apikey.png
MILVUS_TOKEN=your-zilliz-cloud-api-key

# Zilliz Cloud project name to use when auto-resolving address from token (optional, defaults to 'Default Project')
# ZILLIZ_PROJECT_NAME=Default Project


# =============================================================================
# Code Splitter Configuration
Expand Down
1 change: 1 addition & 0 deletions docs/getting-started/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Claude Context supports a global configuration file at `~/.context/.env` to simp
|----------|-------------|---------|
| `MILVUS_TOKEN` | Milvus authentication token. Get [Zilliz Personal API Key](https://github.com/zilliztech/claude-context/blob/master/assets/signup_and_get_apikey.png) | Recommended |
| `MILVUS_ADDRESS` | Milvus server address. Optional when using Zilliz Personal API Key | Auto-resolved from token |
| `ZILLIZ_PROJECT_NAME` | Zilliz Cloud project name to use when auto-resolving address from token | `Default Project` |

### Ollama (Optional)
| Variable | Description | Default |
Expand Down
24 changes: 14 additions & 10 deletions packages/core/src/vectordb/zilliz-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,38 +273,42 @@ export class ClusterManager {
* Static utility method to get address from token using Zilliz Cloud API
* This method will find or create a cluster and return its connect address
* @param token Zilliz Cloud API token
* @param projectName Optional project name (defaults to 'Default Project')
* @returns Connect address for the cluster
*/
static async getAddressFromToken(token?: string): Promise<string> {
static async getAddressFromToken(token?: string, projectName?: string): Promise<string> {
if (!token) {
throw new Error('Token is required when address is not provided');
}

// Use environment variable or default to 'Default Project' for backward compatibility
const targetProjectName = projectName || envManager.get('ZILLIZ_PROJECT_NAME') || 'Default Project';

try {
const clusterManager = new ClusterManager({ token });

// Get Default Project ID
// Get project by name
const projects = await clusterManager.listProjects();
const defaultProject = projects.find(p => p.projectName === 'Default Project');
const targetProject = projects.find(p => p.projectName === targetProjectName);

if (!defaultProject) {
throw new Error('Default Project not found');
if (!targetProject) {
throw new Error(`Project '${targetProjectName}' not found. Available projects: ${projects.map(p => p.projectName).join(', ')}`);
}

// List clusters in the default project
const clustersResponse = await clusterManager.listClusters(defaultProject.projectId);
// List clusters in the target project
const clustersResponse = await clusterManager.listClusters(targetProject.projectId);

if (clustersResponse.clusters.length > 0) {
// Use the first available cluster
const cluster = clustersResponse.clusters[0];
console.log(`🎯 Using existing cluster: ${cluster.clusterName} (${cluster.clusterId})`);
console.log(`🎯 Using existing cluster: ${cluster.clusterName} (${cluster.clusterId}) in project '${targetProjectName}'`);
return cluster.connectAddress;
} else {
// No clusters found, create a free cluster
console.log('📝 No clusters found, creating a new free cluster...');
console.log(`📝 No clusters found in project '${targetProjectName}', creating a new free cluster...`);
const createResponse = await clusterManager.createFreeCluster({
clusterName: `auto-cluster-${Date.now()}`,
projectId: defaultProject.projectId,
projectId: targetProject.projectId,
regionId: 'gcp-us-west1' // Default region
});

Expand Down
4 changes: 4 additions & 0 deletions packages/mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ Copy your Personal Key to replace `your-zilliz-cloud-api-key` in the configurati

```bash
MILVUS_TOKEN=your-zilliz-cloud-api-key

# Optional: Specify Zilliz Cloud project name (defaults to 'Default Project')
# Use this if you want to use a different project when auto-resolving address from token
# ZILLIZ_PROJECT_NAME=My Custom Project
```

#### Embedding Batch Size
Expand Down
4 changes: 3 additions & 1 deletion packages/mcp/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ContextMcpConfig {
// Vector database configuration
milvusAddress?: string; // Optional, can be auto-resolved from token
milvusToken?: string;
zillizProjectName?: string; // Optional, defaults to 'Default Project'
}

// Legacy format (v1) - for backward compatibility
Expand Down Expand Up @@ -130,7 +131,8 @@ export function createMcpConfig(): ContextMcpConfig {
ollamaHost: envManager.get('OLLAMA_HOST'),
// Vector database configuration - address can be auto-resolved from token
milvusAddress: envManager.get('MILVUS_ADDRESS'), // Optional, can be resolved from token
milvusToken: envManager.get('MILVUS_TOKEN')
milvusToken: envManager.get('MILVUS_TOKEN'),
zillizProjectName: envManager.get('ZILLIZ_PROJECT_NAME') // Optional, defaults to 'Default Project'
};

return config;
Expand Down