Skip to content

Commit 8d23c3c

Browse files
committed
lint
1 parent e75a622 commit 8d23c3c

File tree

2 files changed

+31
-36
lines changed

2 files changed

+31
-36
lines changed

DEVELOPMENT.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@ We use GitHub Actions to automate our release process, connecting GitHub Release
7777
```
7878

7979
This will:
80-
8180
- Update the version in package.json
8281
- Create a git tag
8382
- Push the changes and tag to GitHub
8483

8584
2. **Create GitHub Release**:
86-
8785
- Go to GitHub repository → "Releases" → "Draft a new release"
8886
- Choose the tag that was just created
8987
- Fill in release notes detailing what's new, fixes, and any breaking changes
@@ -92,7 +90,6 @@ We use GitHub Actions to automate our release process, connecting GitHub Release
9290
3. **Automated Publishing**:
9391

9492
The GitHub Action will automatically:
95-
9693
- Verify the package version matches the GitHub tag
9794
- Run linting and build checks
9895
- Generate a changelog from commits since the last release
@@ -106,12 +103,10 @@ We use GitHub Actions to automate our release process, connecting GitHub Release
106103
To set up automated publishing:
107104

108105
1. Generate an NPM access token:
109-
110106
- Go to npmjs.com → User Settings → Access Tokens
111107
- Create a new token with "Automation" type and publish permissions
112108

113109
2. Add the token to GitHub repository secrets:
114-
115110
- Go to your GitHub repository → Settings → Secrets → Actions
116111
- Add a new secret named `NPM_TOKEN` with the value of your NPM token
117112

src/agents/mcp_agent.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { StreamEvent } from '@langchain/core/tracers/log_stream'
77
import type { AgentFinish, AgentStep } from 'langchain/agents'
88

99
import type { ZodSchema } from 'zod'
10-
import { zodToJsonSchema } from 'zod-to-json-schema'
1110
import type { MCPClient } from '../client.js'
1211
import type { BaseConnector } from '../connectors/base.js'
1312
import type { MCPSession } from '../session.js'
@@ -25,6 +24,7 @@ import {
2524
AgentExecutor,
2625
createToolCallingAgent,
2726
} from 'langchain/agents'
27+
import { zodToJsonSchema } from 'zod-to-json-schema'
2828
import { LangChainAdapter } from '../adapters/langchain_adapter.js'
2929
import { logger } from '../logging.js'
3030
import { ServerManager } from '../managers/server_manager.js'
@@ -368,7 +368,7 @@ export class MCPAgent {
368368
// Fallback: use the same LLM but we'll handle structure in our helper method
369369
structuredLlm = this.llm
370370
}
371-
schemaDescription = JSON.stringify(zodToJsonSchema(outputSchema), null, 2);
371+
schemaDescription = JSON.stringify(zodToJsonSchema(outputSchema), null, 2)
372372
}
373373

374374
try {
@@ -804,10 +804,10 @@ export class MCPAgent {
804804
// Get detailed schema information for better prompting
805805
const maxRetries = 3
806806
let lastError: string = ''
807-
807+
808808
for (let attempt = 1; attempt <= maxRetries; attempt++) {
809809
logger.info(`🔄 Structured output attempt ${attempt}/${maxRetries}`)
810-
810+
811811
let formatPrompt = `
812812
Please format the following information according to the EXACT schema specified below.
813813
You must use the exact field names and types as shown in the schema.
@@ -842,21 +842,21 @@ export class MCPAgent {
842842
const validatedResult = this._validateStructuredResult(structuredResult, outputSchema)
843843
logger.info(`✅ Structured output successful on attempt ${attempt}`)
844844
return validatedResult
845-
846-
} catch (e) {
845+
}
846+
catch (e) {
847847
lastError = e instanceof Error ? e.message : String(e)
848848
logger.warn(`⚠️ Structured output attempt ${attempt} failed: ${lastError}`)
849-
849+
850850
if (attempt === maxRetries) {
851851
logger.error(`❌ All ${maxRetries} structured output attempts failed`)
852852
throw new Error(`Failed to generate valid structured output after ${maxRetries} attempts. Last error: ${lastError}`)
853853
}
854-
854+
855855
// Continue to next attempt
856856
continue
857857
}
858858
}
859-
859+
860860
// This should never be reached, but TypeScript requires it
861861
throw new Error('Unexpected error in structured output generation')
862862
}
@@ -866,42 +866,42 @@ export class MCPAgent {
866866
*/
867867
private _validateStructuredResult<T>(structuredResult: any, outputSchema: ZodSchema<T>): T {
868868
// Use Zod to validate the structured result
869-
try {
869+
try {
870870
// Use Zod to validate the structured result
871871
const validatedResult = outputSchema.parse(structuredResult)
872872

873-
// Additional validation for required fields
874-
const schemaType = outputSchema as any
875-
if (schemaType._def && schemaType._def.shape) {
876-
for (const [fieldName, fieldSchema] of Object.entries(schemaType._def.shape)) {
877-
const field = fieldSchema as any
878-
const isOptional = field.isOptional?.() ?? field._def?.typeName === 'ZodOptional'
879-
const isNullable = field.isNullable?.() ?? field._def?.typeName === 'ZodNullable'
880-
if (!isOptional && !isNullable) {
881-
const value = (validatedResult as any)[fieldName]
882-
if (value === null || value === undefined
883-
|| (typeof value === 'string' && !value.trim())
884-
|| (Array.isArray(value) && value.length === 0)) {
885-
throw new Error(`Required field '${fieldName}' is missing or empty`)
873+
// Additional validation for required fields
874+
const schemaType = outputSchema as any
875+
if (schemaType._def && schemaType._def.shape) {
876+
for (const [fieldName, fieldSchema] of Object.entries(schemaType._def.shape)) {
877+
const field = fieldSchema as any
878+
const isOptional = field.isOptional?.() ?? field._def?.typeName === 'ZodOptional'
879+
const isNullable = field.isNullable?.() ?? field._def?.typeName === 'ZodNullable'
880+
if (!isOptional && !isNullable) {
881+
const value = (validatedResult as any)[fieldName]
882+
if (value === null || value === undefined
883+
|| (typeof value === 'string' && !value.trim())
884+
|| (Array.isArray(value) && value.length === 0)) {
885+
throw new Error(`Required field '${fieldName}' is missing or empty`)
886+
}
886887
}
887888
}
888889
}
889-
}
890890

891-
return validatedResult
892-
}
893-
catch (e) {
894-
logger.debug(`Validation details: ${e}`)
895-
throw e // Re-raise to trigger retry logic
896-
}
891+
return validatedResult
892+
}
893+
catch (e) {
894+
logger.debug(`Validation details: ${e}`)
895+
throw e // Re-raise to trigger retry logic
896+
}
897897
}
898898

899899
/**
900900
* Enhance the query with schema information to make the agent aware of required fields.
901901
*/
902902
private _enhanceQueryWithSchema<T>(query: string, outputSchema: ZodSchema<T>): string {
903903
try {
904-
const schemaDescription = JSON.stringify(zodToJsonSchema(outputSchema), null, 2);
904+
const schemaDescription = JSON.stringify(zodToJsonSchema(outputSchema), null, 2)
905905

906906
// Enhance the query with schema awareness
907907
const enhancedQuery = `

0 commit comments

Comments
 (0)