> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lyzr.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create MCP OAuth Connection

> Create a named OAuth connection. Match the server’s grant type. For `authorization_code`, supply an allowed `redirect_url`, open the returned `auth_url` in a browser, and refresh the connection status after sign-in. For `client_credentials`, no browser sign-in is needed.

### Endpoint

**POST** `/v3/tools/credentials/oauth`

### Description

Create a named OAuth connection. Match the server’s grant type. For `authorization_code`, supply an allowed `redirect_url`, open the returned `auth_url` in a browser, and refresh the connection status after sign-in. For `client_credentials`, no browser sign-in is needed.

### Authentication

API key (`x-api-key`) in the header.

### Request

```bash theme={null}
curl -X POST 'https://agent-prod.studio.lyzr.ai/v3/tools/credentials/oauth' \
  -H "x-api-key: $LYZR_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"provider_uuid":"<MCP_SERVER_ID>","credential_name":"Support","user_id":"you@example.com","grant_type":"authorization_code","redirect_url":"https://your-app.example.com/oauth/complete"}'
```

### Response

Returns `credential_id` and `status`. An authorization-code connection also returns `auth_url`, `state`, and `expires_at`.


## OpenAPI

````yaml post /tools/credentials/oauth
openapi: 3.0.3
info:
  title: Lyzr MCP Connections API
  version: 1.0.0
servers:
  - url: https://agent-prod.studio.lyzr.ai/v3
security:
  - ApiKeyAuth: []
paths:
  /tools/credentials/oauth:
    post:
      summary: Create MCP OAuth Connection
      description: >-
        Create a named OAuth connection. Match the server’s grant type. For
        `authorization_code`, supply an allowed `redirect_url`, open the
        returned `auth_url` in a browser, and refresh the connection status
        after sign-in. For `client_credentials`, no browser sign-in is needed.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                provider_uuid:
                  type: string
                  description: MCP server ID returned by List MCP Servers.
                credential_name:
                  type: string
                  description: Display name for this connection.
                user_id:
                  type: string
                  description: Your user ID, such as your account email.
                grant_type:
                  type: string
                  enum:
                    - authorization_code
                    - client_credentials
                  default: authorization_code
                redirect_url:
                  type: string
                  description: Required for authorization_code.
                client_id:
                  type: string
                  description: Optional OAuth client override.
                client_secret:
                  type: string
                  description: Optional secret for the override; requires client_id.
              required:
                - provider_uuid
                - credential_name
                - user_id
            example:
              provider_uuid: <MCP_SERVER_ID>
              credential_name: Support
              user_id: you@example.com
              grant_type: authorization_code
              redirect_url: https://your-app.example.com/oauth/complete
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  credential_id:
                    type: string
                    description: ID of the named connection.
                  status:
                    type: string
                    enum:
                      - success
                      - pending
                      - failed
                  external_ref:
                    type: object
                    properties:
                      mcp_server_id:
                        type: string
                        description: MCP server ID.
                      connection_id:
                        type: string
                        description: ID of the named connection.
                  auth_url:
                    type: string
                    description: Browser sign-in URL for authorization_code.
                  state:
                    type: string
                    description: OAuth state for authorization_code.
                  expires_at:
                    type: string
                    format: date-time
        '400':
          description: Invalid request
        '401':
          description: Authentication required
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.