How do I get IntelliSense for Cosmos DB stored procedures in VS Code?

Wayne Blackmon 0 Reputation points
2026-07-02T19:49:27.9733333+00:00

I'm writing Azure Cosmos DB stored procedures in JavaScript, but VS Code doesn't provide IntelliSense for the server-side API. Functions like getContext(), getCollection(), and queryDocuments() are not recognized, and there are no official .d.ts type definitions from Microsoft.

Is there a recommended way to enable IntelliSense or type support for Cosmos DB stored procedures in VS Code?

I'm looking for options such as:

  • community extensions that provide type definitions or snippets
  • custom .d.ts files
  • any official guidance from Microsoft
  • workflows that improve the development experience for server-side JavaScript in Cosmos DB

What is the best approach to get IntelliSense while developing stored procedures, triggers, and UDFs?

Here is a simple stored procedure example showing the issue:

function sample() {
    const context = getContext();
    const collection = context.getCollection();

    const response = context.getResponse();
    response.setBody('Hello from Cosmos DB!');
}
Azure Cosmos DB
Azure Cosmos DB

An Azure NoSQL database service for app development.


1 answer

Sort by: Most helpful
  1. Wayne Blackmon 0 Reputation points
    2026-07-02T19:52:16.63+00:00

    Azure Cosmos DB stored procedures run inside a restricted server-side JavaScript environment that does not expose the normal JavaScript runtime, TypeScript types, or IntelliSense metadata. The server-side objects (getContext(), getCollection(), queryDocuments(), etc.) are injected by the Cosmos DB host and are not part of any standard JavaScript library. Because of this, VS Code cannot provide IntelliSense by default.

    There is no official .d.ts file, npm package, or type definitions published by Microsoft for the server-side API. However, there are a few practical ways to improve the development experience.

    1. Create your own .d.ts file

    You can define the parts of the API you use most often. This enables basic IntelliSense in VS Code.

    Example:

    declare function getContext(): {
      getCollection(): {
        queryDocuments(
          link: string,
          query: string,
          options: any,
          callback: (err: any, docs: any[]) => void
        ): void;
      };
      getResponse(): {
        setBody(body: any): void;
      };
    };
    

    Place this file anywhere in your workspace and VS Code will pick it up.

    2. Use a VS Code extension that provides Cosmos DB server-side IntelliSense

    Some community extensions provide type definitions, snippets, and editor support for stored procedures, triggers, and UDFs.

    One example is the Cosmos DB Toolkit, which provides:

    • IntelliSense for server-side APIs
    • Type definitions for getContext(), getCollection(), queryDocuments(), etc.
    • Snippets for stored procedures, triggers, and UDFs
    • A scratchpad for testing server-side JavaScript

    VS Code Marketplace:
    https://marketplace.visualstudio.com/items?itemName=WayneBlackmon.cosmosdb-toolkit

    GitHub repository:
    https://github.com/wayne-blackmon/cosmosdb-toolkit

    3. Develop stored procedures in normal JS/TS and deploy separately

    Many teams write and test logic in TypeScript (with their own types), then compile and paste the final JavaScript into Cosmos DB. This provides full IntelliSense during development.


    Summary:
    Cosmos DB does not ship IntelliSense or type definitions for its server-side JavaScript runtime. You can create your own .d.ts file, use a community extension that provides type definitions, or develop in TypeScript and deploy compiled JavaScript. These approaches give you IntelliSense support while working with Cosmos DB stored procedures in VS Code.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.