diff --git a/.env.example b/.env.example index 8eb0266a..8e11b922 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/docs/getting-started/environment-variables.md b/docs/getting-started/environment-variables.md index d2b813df..ebaa9794 100644 --- a/docs/getting-started/environment-variables.md +++ b/docs/getting-started/environment-variables.md @@ -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 | diff --git a/packages/core/src/vectordb/zilliz-utils.ts b/packages/core/src/vectordb/zilliz-utils.ts index 0cf560f1..62b9684d 100644 --- a/packages/core/src/vectordb/zilliz-utils.ts +++ b/packages/core/src/vectordb/zilliz-utils.ts @@ -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 { + static async getAddressFromToken(token?: string, projectName?: string): Promise { 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 }); diff --git a/packages/mcp/README.md b/packages/mcp/README.md index 3591ca78..00b48c73 100644 --- a/packages/mcp/README.md +++ b/packages/mcp/README.md @@ -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 diff --git a/packages/mcp/src/config.ts b/packages/mcp/src/config.ts index 428f9474..03947e38 100644 --- a/packages/mcp/src/config.ts +++ b/packages/mcp/src/config.ts @@ -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 @@ -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;