Skip to content

[BUG] Environment variables in MCP Servers configuration seems to not be passed/used correctly #444

@matteo-ladrat-Legrand

Description

@matteo-ladrat-Legrand

Context

I'm trying to put in place a script that will start an agent using the SDK with the Azure DevOps MCP server. For authentication, I need to use the environment variable as specified in the documentation ADO_MCP_AUTH_TOKEN however it seems that passing the environment variables in the MCP server configuration doesn't work at all ...

Image Image

Code

import { CopilotClient } from '@github/copilot-sdk'
import process from 'node:process'

async function main() {
    const client = new CopilotClient({
        autoStart: true,
        autoRestart: false,
        logLevel: 'all',
        githubToken: process.env.GITHUB_TOKEN,
        useStdio: true,
    })

    const env = {
        ADO_MCP_AUTH_TOKEN: process.env.SYSTEM_ACCESSTOKEN
    }

    const session = await client.createSession({
        model: 'gpt-4.1',
        mcpServers: {
            devops: {
                type: 'stdio',
                command: 'npx',
                args: [
                    '-y',
                    '@azure-devops/mcp', process.env.ADO_ORG,
                    '-d', 'core', 'work', 'work-items',
                    '--authentication', 'envvar'
                ],
                env,
                tools: ['*']
            }
        }
    })

    session.on(event => console.dir(event, { depth: 6 }))

    const response = await session.sendAndWait({
        prompt: `In the project "${process.env.ADO_PROJECT}", what does the work item with ID "30026" look like?`
    })
    if (!response) {
        throw new Error('No response received from Copilot')
    }

    console.log('==== Response from Copilot ====')
    console.dir(response, { depth: 6 })
    console.log('==== Response from Copilot ====')

    await session.destroy()
    await client.stop()
}

main()

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions