docs

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HandleDocsCreate            = common.WrapHandler[DocsService](TestableDocsCreate)
	HandleDocsGet               = common.WrapHandler[DocsService](TestableDocsGet)
	HandleDocsGetMetadata       = common.WrapHandler[DocsService](TestableDocsGetMetadata)
	HandleDocsAppendText        = common.WrapHandler[DocsService](TestableDocsAppendText)
	HandleDocsInsertText        = common.WrapHandler[DocsService](TestableDocsInsertText)
	HandleDocsReplaceText       = common.WrapHandler[DocsService](TestableDocsReplaceText)
	HandleDocsDeleteText        = common.WrapHandler[DocsService](TestableDocsDeleteText)
	HandleDocsInsertTable       = common.WrapHandler[DocsService](TestableDocsInsertTable)
	HandleDocsInsertLink        = common.WrapHandler[DocsService](TestableDocsInsertLink)
	HandleDocsBatchUpdate       = common.WrapHandler[DocsService](TestableDocsBatchUpdate)
	HandleDocsFormatText        = common.WrapHandler[DocsService](TestableDocsFormatText)
	HandleDocsClearFormatting   = common.WrapHandler[DocsService](TestableDocsClearFormatting)
	HandleDocsSetParagraphStyle = common.WrapHandler[DocsService](TestableDocsSetParagraphStyle)
	HandleDocsCreateList        = common.WrapHandler[DocsService](TestableDocsCreateList)
	HandleDocsRemoveList        = common.WrapHandler[DocsService](TestableDocsRemoveList)
	HandleDocsInsertPageBreak   = common.WrapHandler[DocsService](TestableDocsInsertPageBreak)
	HandleDocsInsertImage       = common.WrapHandler[DocsService](TestableDocsInsertImage)
	HandleDocsCreateHeader      = common.WrapHandler[DocsService](TestableDocsCreateHeader)
	HandleDocsCreateFooter      = common.WrapHandler[DocsService](TestableDocsCreateFooter)
	HandleDocsGetAsMarkdown     = common.WrapHandler[DocsService](TestableDocsGetAsMarkdown)
	HandleDocsFindAndReplace    = common.WrapHandler[DocsService](TestableDocsFindAndReplace)
	HandleDocsExportToPDF       = common.WrapHandler[DocsService](TestableDocsExportToPDF)
	HandleDocsImportToGoogleDoc = common.WrapHandler[DocsService](TestableDocsImportToGoogleDoc)
	HandleDocsFormatByFind      = common.WrapHandler[DocsService](TestableDocsFormatByFind)
	HandleDocsGetStructure      = common.WrapHandler[DocsService](TestableDocsGetStructure)
	HandleDocsListNamedRanges   = common.WrapHandler[DocsService](TestableDocsListNamedRanges)
	HandleDocsCreateNamedRange  = common.WrapHandler[DocsService](TestableDocsCreateNamedRange)
	HandleDocsDeleteNamedRange  = common.WrapHandler[DocsService](TestableDocsDeleteNamedRange)
	HandleDocsGetSuggestedEdits = common.WrapHandler[DocsService](TestableDocsGetSuggestedEdits)
)
View Source
var DefaultDocsHandlerDeps = common.NewDefaultHandlerDeps(NewDocsService)

DefaultDocsHandlerDeps holds the default dependencies for production use. Initialize with InitDefaultDocsHandlerDeps after SetDeps to pass deps explicitly.

Functions

func InitDefaultDocsHandlerDeps added in v0.1.7

func InitDefaultDocsHandlerDeps(appDeps *common.Deps)

InitDefaultDocsHandlerDeps initializes the default Docs handler deps with explicit deps, avoiding reliance on the global singleton at call time.

func RegisterTools

func RegisterTools(s *server.MCPServer)

RegisterTools registers all Docs tools with the MCP server.

func TestableDocsAppendText

func TestableDocsAppendText(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsAppendText is the testable version of HandleDocsAppendText.

func TestableDocsBatchUpdate

func TestableDocsBatchUpdate(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsBatchUpdate is the testable version of HandleDocsBatchUpdate. Uses raw JSON passthrough to support all Docs API request types, including those not yet in the Go client library's typed Request struct (e.g., updateNamedStyle).

func TestableDocsClearFormatting

func TestableDocsClearFormatting(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsClearFormatting is the testable version of HandleDocsClearFormatting.

func TestableDocsCreate

func TestableDocsCreate(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsCreate is the testable version of HandleDocsCreate.

func TestableDocsCreateFooter

func TestableDocsCreateFooter(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsCreateFooter is the testable version of HandleDocsCreateFooter.

func TestableDocsCreateHeader

func TestableDocsCreateHeader(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsCreateHeader is the testable version of HandleDocsCreateHeader.

func TestableDocsCreateList

func TestableDocsCreateList(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsCreateList is the testable version of HandleDocsCreateList.

func TestableDocsCreateNamedRange added in v0.1.6

func TestableDocsCreateNamedRange(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsCreateNamedRange creates a named range in a document.

func TestableDocsDeleteNamedRange added in v0.1.6

func TestableDocsDeleteNamedRange(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsDeleteNamedRange deletes a named range from a document.

func TestableDocsDeleteText

func TestableDocsDeleteText(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsDeleteText is the testable version of HandleDocsDeleteText.

func TestableDocsExportToPDF added in v0.1.6

func TestableDocsExportToPDF(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsExportToPDF exports a Google Doc, Sheet, or Slides presentation to PDF. Uses the Drive API export endpoint with application/pdf MIME type.

func TestableDocsFindAndReplace added in v0.1.6

func TestableDocsFindAndReplace(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsFindAndReplace searches and replaces text across a Google Doc. Uses the Docs API batchUpdate with ReplaceAllText requests.

func TestableDocsFormatByFind added in v0.1.6

func TestableDocsFormatByFind(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsFormatByFind finds text in a document and applies formatting to all matches. This avoids the need to manually calculate Google Docs internal character indexes.

func TestableDocsFormatText

func TestableDocsFormatText(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsFormatText is the testable version of HandleDocsFormatText.

func TestableDocsGet

func TestableDocsGet(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsGet is the testable version of HandleDocsGet.

func TestableDocsGetAsMarkdown added in v0.1.6

func TestableDocsGetAsMarkdown(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsGetAsMarkdown is the testable version of HandleDocsGetAsMarkdown.

func TestableDocsGetMetadata

func TestableDocsGetMetadata(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsGetMetadata is the testable version of HandleDocsGetMetadata.

func TestableDocsGetStructure added in v0.1.6

func TestableDocsGetStructure(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsGetStructure returns the document's structural elements with real character indices.

func TestableDocsGetSuggestedEdits added in v0.1.6

func TestableDocsGetSuggestedEdits(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsGetSuggestedEdits retrieves all suggested edits in a document.

func TestableDocsImportToGoogleDoc added in v0.1.6

func TestableDocsImportToGoogleDoc(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsImportToGoogleDoc creates a new Google Doc from provided content. Uses the Drive API to upload content with conversion to Google Docs format.

func TestableDocsInsertImage

func TestableDocsInsertImage(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsInsertImage is the testable version of HandleDocsInsertImage.

func TestableDocsInsertLink(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsInsertLink is the testable version of HandleDocsInsertLink.

func TestableDocsInsertPageBreak

func TestableDocsInsertPageBreak(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsInsertPageBreak is the testable version of HandleDocsInsertPageBreak.

func TestableDocsInsertTable

func TestableDocsInsertTable(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsInsertTable is the testable version of HandleDocsInsertTable.

func TestableDocsInsertText

func TestableDocsInsertText(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsInsertText is the testable version of HandleDocsInsertText.

func TestableDocsListNamedRanges added in v0.1.6

func TestableDocsListNamedRanges(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsListNamedRanges lists all named ranges in a document.

func TestableDocsRemoveList

func TestableDocsRemoveList(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsRemoveList is the testable version of HandleDocsRemoveList.

func TestableDocsReplaceText

func TestableDocsReplaceText(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsReplaceText is the testable version of HandleDocsReplaceText.

func TestableDocsSetParagraphStyle

func TestableDocsSetParagraphStyle(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (*mcp.CallToolResult, error)

TestableDocsSetParagraphStyle is the testable version of HandleDocsSetParagraphStyle.

Types

type DocsHandlerDeps

type DocsHandlerDeps = common.HandlerDeps[DocsService]

Type alias using generic types from common package.

type DocsService

type DocsService interface {
	// GetDocument retrieves a document by ID.
	GetDocument(ctx context.Context, documentID string) (*docs.Document, error)

	// GetDocumentWithSuggestions retrieves a document with suggestions inline.
	// This mode shows suggested insertions and deletions alongside the document content.
	GetDocumentWithSuggestions(ctx context.Context, documentID string) (*docs.Document, error)

	// CreateDocument creates a new document with the given title.
	CreateDocument(ctx context.Context, title string) (*docs.Document, error)

	// BatchUpdate performs a batch update on a document.
	BatchUpdate(ctx context.Context, documentID string, requests []*docs.Request) (*docs.BatchUpdateDocumentResponse, error)

	// BatchUpdateRaw performs a batch update using raw JSON, bypassing Go client
	// struct limitations. This supports request types (like updateNamedStyle) that
	// the Go client library has not yet added to its typed Request struct.
	BatchUpdateRaw(ctx context.Context, documentID string, requestsJSON json.RawMessage) (*docs.BatchUpdateDocumentResponse, error)

	// ExportPDF exports a document to PDF format, returning the raw PDF bytes.
	ExportPDF(ctx context.Context, fileID string) ([]byte, *drive.File, error)

	// ImportDocument creates a new Google Doc by uploading content with conversion.
	ImportDocument(ctx context.Context, title string, content []byte, contentType string, parentID string) (*drive.File, error)
}

DocsService defines the interface for Google Docs API operations. This interface enables dependency injection and testing with mocks.

func NewDocsService

func NewDocsService(ctx context.Context, client *http.Client) (DocsService, error)

NewDocsService creates a DocsService from an authenticated HTTP client.

func ResolveDocsServiceOrError

func ResolveDocsServiceOrError(ctx context.Context, request mcp.CallToolRequest, deps *DocsHandlerDeps) (DocsService, *mcp.CallToolResult, bool)

ResolveDocsServiceOrError resolves a Docs service, returning an MCP error result on failure.

type DocsTestFixtures

type DocsTestFixtures struct {
	DefaultEmail string
	MockService  *MockDocsService
	Deps         *DocsHandlerDeps
}

DocsTestFixtures contains test fixtures for Docs tool testing.

func NewDocsTestFixtures

func NewDocsTestFixtures() *DocsTestFixtures

NewDocsTestFixtures creates a new set of test fixtures.

func (*DocsTestFixtures) AddTestDocument

func (f *DocsTestFixtures) AddTestDocument(id, title, content string)

AddTestDocument adds a test document to the mock service.

type MockDocsService

type MockDocsService struct {
	// Documents stores mock document data keyed by document ID
	Documents map[string]*docs.Document

	// ExportedPDFs stores mock PDF data keyed by document ID
	ExportedPDFs map[string][]byte

	// ImportedDocs stores mock imported document data
	ImportedDocs []*drive.File

	// Errors allows tests to configure specific errors for methods
	Errors struct {
		GetDocument    error
		Create         error
		BatchUpdate    error
		BatchUpdateRaw error
		ExportPDF      error
		ImportDocument error
	}

	// Calls tracks method invocations for verification
	Calls struct {
		GetDocument []string
		Create      []string
		BatchUpdate []struct {
			DocumentID string
			Requests   []*docs.Request
		}
		BatchUpdateRaw []struct {
			DocumentID   string
			RequestsJSON json.RawMessage
		}
		ExportPDF      []string
		ImportDocument []struct {
			Title       string
			ContentType string
			ParentID    string
		}
	}
}

MockDocsService implements DocsService for testing.

func NewMockDocsService

func NewMockDocsService() *MockDocsService

NewMockDocsService creates a new mock Docs service with default test data.

func (*MockDocsService) BatchUpdate

func (m *MockDocsService) BatchUpdate(ctx context.Context, documentID string, requests []*docs.Request) (*docs.BatchUpdateDocumentResponse, error)

BatchUpdate performs a mock batch update on a document.

func (*MockDocsService) BatchUpdateRaw added in v0.1.6

func (m *MockDocsService) BatchUpdateRaw(ctx context.Context, documentID string, requestsJSON json.RawMessage) (*docs.BatchUpdateDocumentResponse, error)

BatchUpdateRaw performs a mock batch update using raw JSON.

func (*MockDocsService) CreateDocument

func (m *MockDocsService) CreateDocument(ctx context.Context, title string) (*docs.Document, error)

CreateDocument creates a mock document.

func (*MockDocsService) ExportPDF added in v0.1.6

func (m *MockDocsService) ExportPDF(ctx context.Context, fileID string) ([]byte, *drive.File, error)

ExportPDF exports a mock document as PDF.

func (*MockDocsService) GetDocument

func (m *MockDocsService) GetDocument(ctx context.Context, documentID string) (*docs.Document, error)

GetDocument retrieves a mock document by ID.

func (*MockDocsService) GetDocumentWithSuggestions added in v0.1.6

func (m *MockDocsService) GetDocumentWithSuggestions(ctx context.Context, documentID string) (*docs.Document, error)

GetDocumentWithSuggestions retrieves a mock document (same as GetDocument for testing).

func (*MockDocsService) ImportDocument added in v0.1.6

func (m *MockDocsService) ImportDocument(ctx context.Context, title string, content []byte, contentType string, parentID string) (*drive.File, error)

ImportDocument creates a mock imported document.

type RealDocsService

type RealDocsService struct {
	// contains filtered or unexported fields
}

RealDocsService wraps the Docs API client and implements DocsService.

func NewRealDocsService

func NewRealDocsService(service *docs.Service, driveService *drive.Service) *RealDocsService

NewRealDocsService creates a new RealDocsService wrapping the given API services.

func NewRealDocsServiceWithHTTP added in v0.1.6

func NewRealDocsServiceWithHTTP(service *docs.Service, driveService *drive.Service, httpClient *http.Client) *RealDocsService

NewRealDocsServiceWithHTTP creates a new RealDocsService with an explicit HTTP client for raw API calls that bypass the typed Go client structs.

func (*RealDocsService) BatchUpdate

func (s *RealDocsService) BatchUpdate(ctx context.Context, documentID string, requests []*docs.Request) (*docs.BatchUpdateDocumentResponse, error)

BatchUpdate performs a batch update on a document.

func (*RealDocsService) BatchUpdateRaw added in v0.1.6

func (s *RealDocsService) BatchUpdateRaw(ctx context.Context, documentID string, requestsJSON json.RawMessage) (*docs.BatchUpdateDocumentResponse, error)

BatchUpdateRaw performs a batch update using raw JSON bytes. This bypasses the typed docs.Request struct, allowing request types not yet supported by the Go client library (e.g., updateNamedStyle) to be sent to the API.

func (*RealDocsService) CreateDocument

func (s *RealDocsService) CreateDocument(ctx context.Context, title string) (*docs.Document, error)

CreateDocument creates a new document with the given title.

func (*RealDocsService) ExportPDF added in v0.1.6

func (s *RealDocsService) ExportPDF(ctx context.Context, fileID string) ([]byte, *drive.File, error)

ExportPDF exports a document to PDF format using the Drive API.

func (*RealDocsService) GetDocument

func (s *RealDocsService) GetDocument(ctx context.Context, documentID string) (*docs.Document, error)

GetDocument retrieves a document by ID.

func (*RealDocsService) GetDocumentWithSuggestions added in v0.1.6

func (s *RealDocsService) GetDocumentWithSuggestions(ctx context.Context, documentID string) (*docs.Document, error)

GetDocumentWithSuggestions retrieves a document with suggestions shown inline.

func (*RealDocsService) ImportDocument added in v0.1.6

func (s *RealDocsService) ImportDocument(ctx context.Context, title string, content []byte, contentType string, parentID string) (*drive.File, error)

ImportDocument creates a new Google Doc by uploading content with conversion.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL