MCPcopy Index your code
hub / github.com/microsoft/typespec

github.com/microsoft/typespec @1.13.0

repository ↗ · DeepWiki ↗ · release 1.13.0 ↗ · + Follow
54,077 symbols 174,796 edges 7,518 files 30,723 documented · 57% updated 1d ago@typespec/http-client-js@0.15.0 · 2026-07-03★ 5,7871,057 open issues
README

TypeSpec

Official Docs | Try TypeSpec Online | Getting Started | Language Overview

TypeSpec is a language for defining cloud service APIs and shapes. TypeSpec is a highly extensible language with primitives that can describe API shapes common among REST, OpenAPI, gRPC, and other protocols.

TypeSpec is excellent for generating many different API description formats, client and service code, documentation, and other assets while keeping your TypeSpec definition as a single source of truth.

Using TypeSpec, you can create reusable patterns for all aspects of an API and package those reusable patterns into libraries. These patterns establish "guardrails" for API designers and make it easier to follow best practices than to deviate from them. TypeSpec also has a rich linter framework with the ability to flag anti-patterns as well as an emitter framework that lets you control the output to ensure it follows the patterns you want.

TypeSpec is a Microsoft-built, community-supported project. Your ideas, feedbacks, and code make all the difference and we deeply appreciate the support from the community.

Installation

npm install -g @typespec/compiler

Tools

The TypeSpec VS Code extension can be installed from the VS Code marketplace or directly on the command line:

tsp code install

The TypeSpec VS Extension can be installed from the VS Marketplace or directly on the command line:

tsp vs install

Usage

TypeSpec to OpenAPI 3.0 Example

This example uses the @typespec/http, @typespec/rest, and @typespec/openapi3 libraries to define a basic REST service and generate an OpenAPI 3.0 document from it.

Run the following command and select "Generic REST API":

tsp init

Hit enter a few times to confirm the defaults.

Copy the contents below into your main.tsp:

import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi3";

using Http;
using Rest;

/** This is a pet store service. */
@service(#{ title: "Pet Store Service" })
@server("https://example.com", "The service endpoint")
namespace PetStore;

@route("/pets")
interface Pets {
  list(): Pet[];
}

model Pet {
  @minLength(100)
  name: string;

  @minValue(0)
  @maxValue(100)
  age: int32;

  kind: "dog" | "cat" | "fish";
}

Install the dependencies of main.tsp:

tsp install

Compile it to OpenAPI 3.0:

tsp compile main.tsp --emit @typespec/openapi3

You can find the emitted OpenAPI output in ./tsp-output/openapi.json.

Advanced Scenarios

Installing nightly version

On every commit to the main branch, packages with changes are automatically published to npm with the @next tag. The packages section shows which version corresponds to the next tag for each package.

To use a nightly version of the packages, go over each one of the packages in the package.json file and update it to either the latest published @next version or @latest, whichever is the newest. You can also use the tag latest or next instead of an explicit version.

After updating the package.json file you can run npm update --force. Force is required as there might be some incompatible version requirement.

Example

// Stable setup
"dependencies": {
  "@typespec/compiler": "~0.30.0",
  "@typespec/http": "~0.14.0",
  "@typespec/rest": "~0.14.0",
  "@typespec/openapi": "~0.9.0",
}

// Consume next version
// In this example: compiler and openapi have changes but rest library has none
"dependencies": {
  "@typespec/compiler": "~0.31.0-dev.5",
  "@typespec/http": "~0.14.0",
  "@typespec/rest": "~0.14.0", // No changes to @typespec/rest library so need to stay the latest.
  "@typespec/openapi": "~0.10.0-dev.2",
}

Packages

Name Changelog Latest Next
Core functionality
@typespec/compiler Changelog
TypeSpec Libraries
@typespec/http Changelog
@typespec/rest Changelog
@typespec/openapi Changelog
@typespec/openapi3 Changelog
@typespec/versioning Changelog
TypeSpec Tools
@typespec/prettier-plugin-typespec Changelog
typespec-vs Changelog
typespec-vscode Changelog
tmlanguage-generator Changelog

@next version of the package are the latest versions available on the main branch.

Extension points exported contracts — how you extend this code

Function (Interface)
An immutable client-side representation of Function. [25 implementers]
packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armstreamstyleserialization/models/Function.java
AssetTag (Interface)
(no doc) [34 implementers]
packages/asset-emitter/src/types.ts
DecoratorValidator (Interface)
(no doc) [41 implementers]
packages/compiler/src/core/decorator-utils.ts
NameKit (Interface)
(no doc) [241 implementers]
packages/http-client/src/typekit/kits/utils.ts
HttpCanonicalizationCommon (Interface)
(no doc) [20 implementers]
packages/http-canonicalization/src/http-canonicalization.ts
LogListener (Interface)
(no doc) [4 implementers]
packages/typespec-vscode/src/log/logger.ts
WithKeysScenarioExpect (Interface)
(no doc) [3 implementers]
packages/spec-api/src/scenarios.ts
RouteTree (Interface)
* A tree of routes in an HTTP router domain.
packages/http-server-js/src/http/server/router.ts

Core symbols most depended-on inside this repo

add
called by 3055
packages/http-server-js/src/util/once-queue.ts
expect
called by 2851
packages/compiler/src/testing/rule-tester.ts
equals
called by 2446
packages/compiler/src/core/numeric.ts
getEndpoint
called by 2296
packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armresourceprovider/fluent/ArmClient.java
map
called by 2121
packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/IMapper.java
get
called by 1829
packages/http-client-java/generator/http-client-generator-test/src/main/java/azure/resourcemanager/resources/models/Nesteds.java
ok
called by 1651
packages/spec-api/src/match-engine.ts
push
called by 1513
packages/asset-emitter/src/builders/array-builder.ts

Shape

Method 38,346
Function 7,711
Class 5,191
Interface 2,625
Enum 204

Languages

Java76%
TypeScript18%
Python6%

Modules by API surface

packages/compiler/src/core/checker.ts344 symbols
packages/http-client-python/tests/unit/test_model_base_serialization.py301 symbols
packages/compiler/src/core/types.ts264 symbols
packages/http-client-python/generator/pygen/codegen/models/primitive_types.py166 symbols
packages/compiler/src/core/parser.ts156 symbols
packages/http-client-java/generator/http-client-generator-test/src/main/java/specialwords/implementation/ParametersImpl.java139 symbols
packages/http-client-java/generator/http-client-generator-test/src/main/java/specialwords/implementation/OperationsImpl.java135 symbols
packages/http-client-java/generator/http-client-generator-test/src/main/java/specialwords/implementation/ModelsImpl.java135 symbols
packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/response/implementation/ResponseClientImpl.java105 symbols
packages/asset-emitter/src/type-emitter.ts104 symbols
packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/extension/plugin/JavaSettings.java100 symbols
packages/http-client-python/tests/unit/test_model_base_xml_serialization.py99 symbols

Dependencies from manifests, versioned

com.azure:azure-core1.57.1 · 1×
com.azure:azure-core-http-netty1.16.3 · 1×
com.azure:azure-core-management1.19.3 · 1×
com.azure:azure-core-test1.27.0-beta.14 · 1×
com.azure:azure-identity1.18.2 · 1×
com.azure:azure-json1.5.1 · 1×
com.azure:azure-xml1.2.1 · 1×
com.fasterxml.jackson.datatype:jackson-datatype-jsr3102.18.4 · 1×
com.github.javaparser:javaparser-core3.27.0 · 1×
com.microsoft.typespec:http-client-generator-core1.0.0-beta.1 · 1×

For agents

$ claude mcp add typespec \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact